omics_coordinate/math.rs
1//! Arithmetic operations.
2
3/// Safe addition.
4pub trait CheckedAdd<T>: Sized {
5 /// The output type.
6 type Output;
7
8 /// Adds two items.
9 ///
10 /// - If the addition occurs succesfully, then [`Some<Self>`] is returned.
11 /// - If the addition would overflow, [`None`] is returned.
12 fn checked_add(&self, rhs: T) -> Option<Self::Output>;
13}
14
15/// Safe subtraction.
16pub trait CheckedSub<T>: Sized {
17 /// The output type.
18 type Output;
19
20 /// Subtracts two items.
21 ///
22 /// - If the subtraction occurs successfully, then [`Some<Self>`] is
23 /// returned.
24 /// - If the subtraction would overflow, [`None`] is returned.
25 fn checked_sub(&self, rhs: T) -> Option<Self::Output>;
26}