#update #struct #partial-eq #10 #approch #bla

opdater

Small trait based approch to struct updates

2 releases

new 0.1.1 Mar 4, 2025
0.1.0 Mar 4, 2025

#1230 in Rust patterns

Download history 174/week @ 2025-02-28

174 downloads per month

ISC license

5KB

Opdater

Small trait based approch to implement updating of structs.

The main goal of this crate is to allow updating a struct continously without writing a lot of boilerplate code.

Example

use opdater::Opdater;

#[derive(Debug, PartialEq, Opdater)]
struct Bla {
    a: Option<i32>,
    b: Option<f32>,
}

let mut bla = Bla { a: None, b: None };
let bla_op = Bla {
    a: Some(10),
    b: Some(13.37),
};

bla.update(bla_op);

assert_eq!(
    bla,
    Bla {
        a: Some(10),
        b: Some(13.37)
    }
);

let bla_op2 = Bla {
    a: Some(5),
    b: None,
};

bla.update(bla_op2);

assert_eq!(
    bla,
    Bla {
        a: Some(5),
        b: Some(13.37)
    }
);

Etmylogy

Opdater means to update in Danish.

License

This is licensed under the ISC License


lib.rs:

Opdater

Small trait based approch to implement updating of structs.

The main goal of this crate is to allow updating a struct continously without writing a lot of boilerplate code.

Example

use opdater::Opdater;

#[derive(Debug, PartialEq, Opdater)]
struct Bla {
    a: Option<i32>,
    b: Option<f32>,
}

let mut bla = Bla { a: None, b: None };
let bla_op = Bla {
    a: Some(10),
    b: Some(13.37),
};

bla.update(bla_op);

assert_eq!(
    bla,
    Bla {
        a: Some(10),
        b: Some(13.37)
    }
);

let bla_op2 = Bla {
    a: Some(5),
    b: None,
};

bla.update(bla_op2);

assert_eq!(
    bla,
    Bla {
        a: Some(5),
        b: Some(13.37)
    }
);

Etmylogy

Opdater means to update in Danish.

License

This is licensed under the ISC License

Dependencies

~200–630KB
~15K SLoC