Skip to content

Commit 77324ee

Browse files
authored
Merge pull request #53 from MiguelX413/master
Add Integer.dec() and Integer.inc()
2 parents 9720c90 + 8682553 commit 77324ee

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/lib.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,40 @@ pub trait Integer: Sized + Num + PartialOrd + Ord + Eq {
335335
{
336336
self.clone() - self.mod_floor(other)
337337
}
338+
339+
/// Decrements self by one.
340+
///
341+
/// # Examples
342+
///
343+
/// ~~~
344+
/// # use num_integer::Integer;
345+
/// let mut x: i32 = 43;
346+
/// x.dec();
347+
/// assert_eq!(x, 42);
348+
/// ~~~
349+
fn dec(&mut self)
350+
where
351+
Self: Clone,
352+
{
353+
*self = self.clone() - Self::one()
354+
}
355+
356+
/// Increments self by one.
357+
///
358+
/// # Examples
359+
///
360+
/// ~~~
361+
/// # use num_integer::Integer;
362+
/// let mut x: i32 = 41;
363+
/// x.inc();
364+
/// assert_eq!(x, 42);
365+
/// ~~~
366+
fn inc(&mut self)
367+
where
368+
Self: Clone,
369+
{
370+
*self = self.clone() + Self::one()
371+
}
338372
}
339373

340374
/// Greatest common divisor and Bézout coefficients

0 commit comments

Comments
 (0)