deep-struct-update

Crates.iodeep-struct-update
lib.rsdeep-struct-update
version0.1.0
sourcesrc
created_at2023-12-27 08:31:32.26941
updated_at2023-12-27 08:31:32.26941
descriptionStruct update syntax with nesting.
homepage
repositoryhttps://gitlab.com/konnorandrews/deep-struct-update
max_upload_size
id1081517
size18,552
Konnor Andrews (konnorandrews)

documentation

README

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

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 deep-struct-update by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Commit count: 2

cargo fmt