Crates.io | no_mangle_pub_export_c_fn |
lib.rs | no_mangle_pub_export_c_fn |
version | 0.1.2 |
source | src |
created_at | 2021-12-24 22:34:38.084316 |
updated_at | 2021-12-25 00:47:07.142325 |
description | A library for extracting #[no_mangle] pub extern "C" functions. |
homepage | |
repository | https://github.com/JohnScience/no_mangle_pub_export_c_fn |
max_upload_size | |
id | 502799 |
size | 38,674 |
In order to expose a function with C binary interface for interoperability with other programming languages, Rust developers should use #[no_mangle] attribute and specify ABI for the declared function.
#[no_mangle]
pub extern "C" fn func_name () /* -> ... */ {
// ...
}
You can read about it more here
This library allows to perform syn-driven parsing for obtaining the information about location of these no-mangle-pub-extern-C functions.
main.rs
use no_mangle_pub_export_c_fn::{parse_for_no_mangle_pub_extern_c_fns, ParsedFile};
fn main() {
let crate_root = std::env::var("CARGO_MANIFEST_DIR").unwrap();
let parsed_files: Vec<ParsedFile> = parse_for_no_mangle_pub_extern_c_fns(crate_root.as_str());
println!("{:#?}", parsed_files);
}
unused.rs
#[no_mangle]
pub extern "C" fn s() {
// test
}
[
ParsedFile {
path: "...\\no_mangle_pub_export_c_fn\\src\\lib.rs",
no_mangle_pub_export_c_fns: NoManglePubExportCFns {
no_mangle_pub_export_c_fn_vec: [],
},
},
ParsedFile {
path: "...\\no_mangle_pub_export_c_fn\\src\\main.rs",
no_mangle_pub_export_c_fns: NoManglePubExportCFns {
no_mangle_pub_export_c_fn_vec: [],
},
},
ParsedFile {
path: "...\\no_mangle_pub_export_c_fn\\src\\unused.rs",
no_mangle_pub_export_c_fns: NoManglePubExportCFns {
no_mangle_pub_export_c_fn_vec: [
NoManglePubExportCFnEnds {
start_line: 1,
start_column: 0,
end_line: 4,
end_column: 1,
},
],
},
},
]
All structures in this library implement Serialize and Deserialize traits from serde. Because of that you can convert into many data formats supporting serde.