repr_c_pub_struct

Crates.iorepr_c_pub_struct
lib.rsrepr_c_pub_struct
version0.1.1
sourcesrc
created_at2021-12-26 20:10:00.726047
updated_at2022-03-13 05:25:29.322046
descriptionA library for extracting `#[repr(C)] pub struct`ures.
homepage
repositoryhttps://github.com/JohnScience/repr_c_pub_struct
max_upload_size
id503434
size38,150
Dmitrii - Demenev (JohnScience)

documentation

https://docs.rs/repr_c_pub_struct

README

A library for extracting #[repr(C)] pub structures

In order to expose a struct with stable ABI for interoperability with other programming languages, Rust developers should use #[repr(C)] attribute.

#[repr(C)]
pub struct Great {
    
}

You can read about it more here

This library allows to perform syn-driven parsing for obtaining the information about location of these repr-c-pub-structs.

Example

src/main.rs

use repr_c_pub_struct::parse_for_repr_c_pub_structs;
fn main() {
    let crate_root = std::env::var("CARGO_MANIFEST_DIR").unwrap();
    let repr_c_structs = parse_for_repr_c_pub_structs(crate_root.as_str());
    println!("{:#?}", repr_c_structs);
}

src/unused.rs

#[repr(C)]
pub struct Unused {
   // Test
}

Output on Windows

[
    ParsedFile {
        path: "...\\repr_c_pub_struct\\src\\lib.rs",
        repr_c_pub_structs: ReprCPubStructs(
            [],
        ),
    },
    ParsedFile {
        path: "...\\repr_c_pub_struct\\src\\main.rs",
        repr_c_pub_structs: ReprCPubStructs(
            [],
        ),
    },
    ParsedFile {
        path: "...\\repr_c_pub_struct\\src\\unused.rs",
        repr_c_pub_structs: ReprCPubStructs(
            [
                LineColumnEnds {
                    start_line: 1,
                    start_column: 0,
                    end_line: 4,
                    end_column: 1,
                },
            ],
        ),
    },
]

Note

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

Seralization & Deserialization

All structures in this library implement Serialize and Deserialize traits from serde. Because of that you can convert into many data formats supporting serde.

Data formats

  • 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.

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Commit count: 4

cargo fmt