Crate no_mangle_pub_export_c_fn[][src]

Expand description

This is a library that is meant to help exporting Rust code to other languages by providing a parse_for_no_mangle_pub_extern_c_fns function. This function accepts a path to the crate root and recursively traverses all directories in src/** returning Vec<ParsedFile>.

Hierarchy of structs

src
src
main.rs
main.rs
lib.rs
lib.rs
filename.rs
filename.rs
#[no_mangle]
pub extern “C” fn func_name (…) -> … {
// …
}
#[no_mangle]…
#[no_mangle]
pub extern “C” fn func_name (…) -> … {
// …
}
#[no_mangle]…
LineColumnEnds {
    start_line,
    start_column,
    end_line,
    end_column,
}
LineColumnEnds {…
filename.rs
filename.rs
LineColumnEnds
LineColumnEnds
NoManglePubExportCFns
NoManglePubExportCFns
ParsedFile
ParsedFile
Viewer does not support full SVG 1.1

Example

main.rs

use no_mangle_pub_export_c_fn::{parse_for_no_mangle_pub_extern_c_fns, ParsedFile};
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);

Output on Windows

[
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,
            },
        ],
    },
},
]

Note

The paths will be absolute. The prefixes have been deleted intentionally.

Integration with serde

Serde is an amazing framework for serializing and deserializing Rust data structures efficiently and generically. The following is a partial list of data formats that have been implemented for Serde by the community.

  • JSON, the ubiquitous JavaScript Object Notation used by many HTTP APIs.
  • Bincode, a compact binary format used for IPC within the Servo rendering engine.
  • CBOR, a Concise Binary Object Representation designed for small message size without the need for version negotiation.
  • YAML, a self-proclaimed human-friendly configuration language that ain’t markup language.
  • MessagePack, an efficient binary format that resembles a compact JSON.
  • TOML, a minimal configuration format used by Cargo.
  • Pickle, a format common in the Python world.
  • RON, a Rusty Object Notation.
  • BSON, the data storage and network transfer format used by MongoDB.
  • Avro, a binary format used within Apache Hadoop, with support for schema definition.
  • JSON5, a superset of JSON including some productions from ES5.
  • Postcard, a no_std and embedded-systems friendly compact binary format.
  • URL query strings, in the x-www-form-urlencoded format.
  • Envy, a way to deserialize environment variables into Rust structs. (deserialization only)
  • Envy Store, a way to deserialize AWS Parameter Store parameters into Rust structs. (deserialization only)
  • S-expressions, the textual representation of code and data used by the Lisp language family.
  • D-Bus’s binary wire format.
  • FlexBuffers, the schemaless cousin of Google’s FlatBuffers zero-copy serialization format.
  • DynamoDB Items, the format used by rusoto_dynamodb to transfer data to and from DynamoDB.

F.A.Q.

Structs

The location information of an individual #[no_mangle] pub export "C" function.

The newtype of Vec<LineColumnEnds>. When accessed from the result of parse_for_no_mangle_pub_extern_c_fns(_), contains location information about #[no_mangle] pub export "C" functions in a particular file.

The struct that contains the path to the parsed file and a collection of location information about #[no_mangle] pub export "C" functions in that file.

Functions

Checks if the given syn::ItemFn is a #[no_mangle] pub export “C”` function.

Traverses all directories in crate_root/src/** filtering Rust source files, parsing them and returning a collection of location information of #[no_mangle] pub export "C" functions in each file.