deep-struct-update 0.1.0

Struct update syntax with nesting.
Documentation
  • Coverage
  • 100%
    2 out of 2 items documented2 out of 2 items with examples
  • Size
  • Source code size: 18.21 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 160.74 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • konnorandrews/deep-struct-update
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • konnorandrews

Version Crates.io docs.rs Crates.io

::deep-struct-update

Struct update syntax with support for nested structs.

use deep_struct_update::update;

struct Person {
    name: String,
    job: Job,
    age: u8
}

struct Job {
    position: String,
    company: String
}

let bob = Person {
    name: String::from("Bob"),
    job: Job {
        position: String::from("Programmer"),
        company: String::from("Evil Inc.")
    },
    age: 29
};

let alice = update! {
    name: String::from("Alice"),
    age: 31,
    job: {
        position: String::from("Senior Programmer")
    }
    ..bob
};

assert_eq!(alice.age, 31);
assert_eq!(alice.name, "Alice");
assert_eq!(alice.job.position, "Senior Programmer");
assert_eq!(alice.job.company, "Evil Inc.");

License