pub trait UpSet<T, Marker> {
// Required method
fn up_set(self, value: T) -> T;
}Expand description
Set a new value, or compute it using a closure.
§Examples
use up_set::UpSet;
#[derive(Debug, Eq, PartialEq)]
struct Person {
age: u8
}
impl Person {
fn age<M, U: UpSet<u8, M>>(mut self, up_set: U) -> Self {
self.age = up_set.up_set(self.age);
self
}
}
// Set age to 4
assert_eq!(Person { age: 55 }.age(4), Person { age: 4 });
// Add +4 to existing age
assert_eq!(Person { age: 55 }.age(|age| age + 4), Person { age: 59 });See the crate-level documentation for more info.