Skip to content

Kolsky/late_init

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

late_init

Partially initialize fields with the rest filled as defaults.

Provides a LateInit derive macro which brings in scope a struct NameLateInit created from struct Name definition.

Then it can be used as follows:

#[derive(Defailt)]
struct HasDefault;
struct NoDefault;

#[derive(LateInit)]
struct Name {
    a: HasDefault,
    b: NoDefault,
    c: HasDefault,
    /*insert multiple field defs similar to a*/
    x: HasDefault,
    y: HasDefault,
    z: NoDefault,
}

fn create_name() -> Name {
    NameLateInit::default()
        .b(NoDefault) // You have to provide fields which do not have default impl
        .x(HasDefault) // These are optional
        .z(NoDefault)
        .finish()
}

May as well serve as an alternative to derive-new.

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.

About

No description, website, or topics provided.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages