Walk over compile-time designated Rust types at run-time.

Kestrel 653067f003 Add support for references/lifetimes, broader std support, and more docs. преди 3 години
rustructure 653067f003 Add support for references/lifetimes, broader std support, and more docs. преди 3 години
rustructure-macros 653067f003 Add support for references/lifetimes, broader std support, and more docs. преди 3 години
rustructure-test 653067f003 Add support for references/lifetimes, broader std support, and more docs. преди 3 години
.gitignore 9405467ae2 Initial working version. преди 3 години
.vimrc 9405467ae2 Initial working version. преди 3 години
Cargo.lock 28a08de6ee Added skip_walk attribute. преди 3 години
Cargo.toml 9405467ae2 Initial working version. преди 3 години
README.md 653067f003 Add support for references/lifetimes, broader std support, and more docs. преди 3 години

README.md

rustructure supports walking over designated Rust types at run-time.

This allows for some level of introspection from the perspective of libraries that consume external types that can be prepared for their consumption. One motivating example is when generating code for serialization or deserialization as a complement to serde when a format requires foreknowledge of the type at a time it is impossible to have an actual instance of the type.

This crate can be no_std by removing the default std feature, though without at least alloc its usefulness is likely limited until generic associated types land in stable.

The main features of this library are the Walkable trait/derive macro and Walker trait. A simple example Walker that produces an S-expression-like representation of a data type is included as StringWalker (unavailable in no_std):

use rustructure::Walkable;

#[derive(Walkable)]
struct ExampleStruct<'l> {
    a: Option<u8>,
    b: &'l str,
    c: (u64, String)
}

assert_eq!(
    rustructure::StringWalker::walk::<ExampleStruct>(),
    "(struct:ExampleStruct \
        (field:a (option integer)) \
        (field:b str) \
        (field:c (tuple \
            (field:0 integer) \
            (field:1 str)\
            )\
        )\
    )".to_string()
);