scsys_traits/
adjust.rs

1/*
2   Appellation: adjust <traits>
3   Contrib: FL03 <jo3mccain@icloud.com>
4*/
5use core::ops::{Add, Sub};
6use num_traits::One;
7
8pub trait Adjust<T> {
9    type Output;
10
11    fn adjust(&mut self, adjust: T) -> Self::Output;
12}
13
14/// `Decrement` is a trait describing the ability to decrement a value.
15///
16pub trait Decrement {
17    type Output;
18
19    fn dec(&self) -> Self::Output;
20}
21
22pub trait Increment {
23    type Output;
24
25    fn inc(&self) -> Self::Output;
26}
27
28/*
29 ******** implementations ********
30*/
31impl<S, T> Decrement for S
32where
33    S: One,
34    for<'a> &'a S: Sub<S, Output = T>,
35{
36    type Output = T;
37
38    fn dec(&self) -> Self::Output {
39        self - S::one()
40    }
41}
42
43impl<S, T> Increment for S
44where
45    S: One,
46    for<'a> &'a S: Add<S, Output = T>,
47{
48    type Output = T;
49
50    fn inc(&self) -> Self::Output {
51        self + S::one()
52    }
53}