concision_traits/ops/
unary.rs

1/*
2    Appellation: unary <module>
3    Created At: 2025.12.09:07:26:04
4    Contrib: @FL03
5*/
6/// [`Decrement`] is a chainable trait that defines a decrement method,
7/// effectively removing a single unit from the original object to create another
8pub trait Decrement {
9    type Output;
10
11    fn dec(self) -> Self::Output;
12}
13
14/// The [`DecrementMut`] trait defines a decrement method that operates in place,
15/// modifying the original object.
16pub trait DecrementMut {
17    fn dec_mut(&mut self);
18}
19/// The [`Increment`]
20pub trait Increment {
21    type Output;
22
23    fn inc(self) -> Self::Output;
24}
25
26pub trait IncrementMut {
27    fn inc_mut(&mut self);
28}
29
30/*
31 ************* Implementations *************
32*/
33use num_traits::One;
34
35impl<T> Decrement for T
36where
37    T: One + core::ops::Sub<Output = T>,
38{
39    type Output = T;
40
41    fn dec(self) -> Self::Output {
42        self - T::one()
43    }
44}
45
46impl<T> DecrementMut for T
47where
48    T: One + core::ops::SubAssign,
49{
50    fn dec_mut(&mut self) {
51        *self -= T::one()
52    }
53}
54
55impl<T> Increment for T
56where
57    T: One + core::ops::Add<Output = T>,
58{
59    type Output = T;
60
61    fn inc(self) -> Self::Output {
62        self + T::one()
63    }
64}