Skip to main content

SaturatingAddSigned

Derive Macro SaturatingAddSigned 

Source
#[derive(SaturatingAddSigned)]
{
    // Attributes available to this derive:
    #[saturating_add_signed]
}
Expand description

Implements mkutils::SaturatingAddSigned for a struct by delegating to each field. Set the Signed associated type and bounds with #[saturating_add_signed(assoc(type Signed = Point<<T as SaturatingAddSigned>::Signed>)), bound = "T: SomeTrait"]

ยงExample

โ“˜
#[derive(Debug, mkutils_macros::SaturatingAddSigned, PartialEq)]
#[saturating_add_signed(assoc(type Signed = MyStruct<<T as SaturatingAddSigned>::Signed>))]
struct MyStruct<T>(T, T);

adds

โ“˜
impl mkutils::SaturatingAddSigned for MyStruct<T> {
    fn saturating_add_signed(&self, v: &Other) -> Self {
        Self(self.0.saturating_add_signed(&v.0), self.1.saturating_add_signed(&v.1))
    }
}

as can be seen in

โ“˜
std::assert_eq!(MyStruct(2, 2).saturating_add_signed(MyStruct(-1, -1)), MyStruct(1, 1));