Skip to content

Commit

Permalink
Add examples to dec/inc
Browse files Browse the repository at this point in the history
  • Loading branch information
cuviper committed Feb 8, 2024
1 parent 9d4d68b commit 8682553
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/lib.rs
Expand Up @@ -336,15 +336,33 @@ pub trait Integer: Sized + Num + PartialOrd + Ord + Eq {
self.clone() - self.mod_floor(other)
}

/// Decrements self.
/// Decrements self by one.
///
/// # Examples
///
/// ~~~
/// # use num_integer::Integer;
/// let mut x: i32 = 43;
/// x.dec();
/// assert_eq!(x, 42);
/// ~~~
fn dec(&mut self)
where
Self: Clone,
{
*self = self.clone() - Self::one()
}

/// Increments self.
/// Increments self by one.
///
/// # Examples
///
/// ~~~
/// # use num_integer::Integer;
/// let mut x: i32 = 41;
/// x.inc();
/// assert_eq!(x, 42);
/// ~~~
fn inc(&mut self)
where
Self: Clone,
Expand Down

0 comments on commit 8682553

Please sign in to comment.