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

Kestrel d53dfc1823 Add README symlink. 2 anos atrás
rustructure d53dfc1823 Add README symlink. 2 anos atrás
rustructure-macros d00089ace9 Bump version for publishing, expand manifests, minor doc update. 2 anos atrás
rustructure-test d00089ace9 Bump version for publishing, expand manifests, minor doc update. 2 anos atrás
.gitignore 9405467ae2 Initial working version. 2 anos atrás
.vimrc 9405467ae2 Initial working version. 2 anos atrás
Cargo.lock d00089ace9 Bump version for publishing, expand manifests, minor doc update. 2 anos atrás
Cargo.toml 9405467ae2 Initial working version. 2 anos atrás
README.md d00089ace9 Bump version for publishing, expand manifests, minor doc update. 2 anos atrás

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()
);

If it is of interest, you can find test cases for the library (via StringWalker) in the unpublished rustructure-test crate in the source repository.