<commit_before>// use to create a .so/.dll
#![crate_type = "dylib"]

extern crate libc;
use std::string::raw::from_buf;

// used to have this use function callable from C
// 1. no_mangle garanty the name will stay rust_print
// 2. pub extern garanty the name is exported
#[no_mangle]
pub extern fn rust_print(value: *const libc::c_char) {

    // unsafe block because we're not sure if the pointer
    // given by this library is legit (we could receive a null
    // pointer, or pointer on value that can't be converted to
    // a UTF-8 string etc.

    // note we need to cast "as *const u8" because for a reason that
    // I can't explain,  libc::c_char is i8 ...
    let string = unsafe { from_buf(value as *const u8) };
    
    println!("haha im from rust {}", string)
}
<commit_msg>added a little more explanation in C string to rust<commit_after>// use to create a .so/.dll
#![crate_type = "dylib"]

extern crate libc;
use std::string::raw::from_buf;

// used to have this function callable from C
// 1. no_mangle garanty the name will stay rust_print
// 2. pub extern garanty the name is exported

#[no_mangle]
pub extern fn rust_print(
    // note that we use "* const libc::c_char" to
    // represent a string coming from C code
    value: *const libc::c_char
) {

    // unsafe block because we're not sure if the pointer
    // given by this library is legit (we could receive a null
    // pointer, or pointer on value that can't be converted to
    // a UTF-8 string etc.

    // note we need to cast "as *const u8" because for a reason that
    // I can't explain,  libc::c_char is i8 ...
    let string = unsafe { from_buf(value as *const u8) };
    
    println!("haha im from rust {}", string)
}

{'fraction_non_alphanumeric': 0.10419091967403958, 'fraction_numerical': 0.006984866123399301, 'mean_word_length': 2.880361173814898, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6853070', 'n_tokens_mistral': 558, 'n_tokens_neox': 530, 'n_words': 243}