Crates.io | crabi_test2 |
lib.rs | crabi_test2 |
version | 0.1.0 |
source | src |
created_at | 2024-11-06 09:54:15.257995 |
updated_at | 2024-11-06 09:54:15.257995 |
description | An experimental Rust library for advanced ABI exploration and cross-language interoperability. |
homepage | |
repository | https://github.com/bensatlantik/crabi_test2 |
max_upload_size | |
id | 1438051 |
size | 10,498 |
crabi_test2 is an experimental Rust library designed to facilitate advanced exploration and understanding of Application Binary Interface (ABI) concepts, particularly as they relate to cross-language interoperability and Rust’s Foreign Function Interface (FFI).
#[repr(C)]
data structures to understand how Rust data can be made ABI-compliant.extern "C"
functions that show how data is passed and modified between Rust and other languages.crabi_test2 is suitable for:
To install crabi_test2
, add it to your Cargo.toml
:
[dependencies]
crabi_test2 = "0.1.0"
thiserror = "1.0"
use crabi_test2::{SimpleData, modify_simple_data, CallbackData, register_callback, trigger_callback, ComplexData, process_complex_data};
fn main() {
// Example usage of SimpleData and modify_simple_data
let mut data = SimpleData {
value: 0,
flag: false,
};
// Call the function to modify the data
modify_simple_data(&mut data as *mut _);
// Print the modified data
println!("Value: {}, Flag: {}", data.value, data.flag);
// Example usage of CallbackData
extern "C" fn callback_fn(val: i32) {
println!("Callback called with value: {}", val);
}
let mut callback_data = CallbackData {
value: 42,
callback: None,
};
// Register and trigger the callback
register_callback(&mut callback_data as *mut _, callback_fn);
trigger_callback(&mut callback_data as *mut _);
// Example usage of ComplexData and process_complex_data
extern "C" fn complex_callback(data: *const ComplexData) {
unsafe {
println!("ComplexData Callback with ID: {}", (*data).id);
}
}
let mut complex_data = ComplexData {
id: 1,
name: "Example".as_ptr(),
name_len: 7,
values: [1.0, 2.0, 3.0, 4.0, 5.0],
callback: Some(complex_callback),
};
process_complex_data(&mut complex_data as *mut
Distributed under the MIT or Apache 2.0 license.
Ben Santora bensatlantik@gmail.com