Skip to content

substruct is a macro to easily deal with sub structure

License

Notifications You must be signed in to change notification settings

massalabs/substruct

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

substruct

substruct is a macro to easily deal with sub structure

example

use substruct::SubStruct;

// A 'config' struct with lot of fields

pub struct Config {
    a: i32,
    b: u32,
    c: f32,
    d: f64,
}

// A 'sub config' of 'config' 

#[derive(Debug)]
#[derive(SubStruct)]
#[parent(type = "Config")]
pub struct SubConfig {
    c: f32,
    d: f64,
}

fn main() {
    let cfg = Config {
        a: -3,
        b: 2,
        c: 4.2,
        d: 0.4242422110,
    };

    // the macro auto. generates: impl From<&Config> for SubConfig
    // so you can use:
    let sc: SubConfig = (&cfg).into();
}

About

substruct is a macro to easily deal with sub structure

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 100.0%