Skip to main content

SaturatingAdd

Derive Macro SaturatingAdd 

Source
#[derive(SaturatingAdd)]
Expand description

Implements num::traits::SaturatingAdd for a struct by delegating to each field.

ยงExample

#[derive(SaturatingAdd)]
struct MyStruct(usize);

adds

impl num::traits::SaturatingAdd for MyStruct {
    fn saturating_add(&self, v: &Self) -> Self {
        Self(self.0.saturating_add(&v.0))
    }
}