pub struct Bint {
pub value: u8,
pub boundary: u8,
}Expand description
Bint: A bounded integer.
Returns a struct that represents an unsigned integer and a boundary that represents when the value will be reset to 0.
Usage:
use bint::Bint;
let b = Bint {value: 5, boundary: 6 };
let c: Bint = b.up();
let d: Bint = c.up();
assert_eq!(5, b.value);
assert_eq!(0, c.value);
assert_eq!(1, d.value);Fields§
§value: u8§boundary: u8Implementations§
Source§impl Bint
impl Bint
Sourcepub fn new(boundary: u8) -> Bint
pub fn new(boundary: u8) -> Bint
use bint::Bint;
let b: Bint = Bint::new(6);
let c: Bint = b.down();
let d: Bint = c.up();
let e: Bint = d.up();
assert_eq!(0, b.value);
assert_eq!(5, c.value);
assert_eq!(0, d.value);
assert_eq!(1, e.value);Sourcepub fn new_with_value(boundary: u8, value: u8) -> Bint
pub fn new_with_value(boundary: u8, value: u8) -> Bint
use bint::Bint;
let bint = Bint::new_with_value(10, 7);
assert_eq!(10, bint.boundary);
assert_eq!(7, bint.value);
let bint_out_of_range = Bint::new_with_value(10, 23);
assert_eq!(10, bint_out_of_range.boundary);
assert_eq!(0, bint_out_of_range.value);Sourcepub fn up(&self) -> Bint
pub fn up(&self) -> Bint
use bint::Bint;
let b: Bint = Bint {
value: 4,
boundary: 6,
};
let b: Bint = b.up();
assert_eq!(5, b.value);
let b: Bint = b.up();
assert_eq!(0, b.value);Sourcepub fn up_x(self, x: u8) -> Bint
pub fn up_x(self, x: u8) -> Bint
use bint::Bint;
let b: Bint = Bint {
value: 4,
boundary: 6,
};
let b: Bint = b.up_x(3);
assert_eq!(1, b.value);Trait Implementations§
Source§impl From<&DrainableBintCell> for Bint
impl From<&DrainableBintCell> for Bint
Source§fn from(cell: &DrainableBintCell) -> Self
fn from(cell: &DrainableBintCell) -> Self
use bint::{Bint, DrainableBintCell};
let bint_cell = DrainableBintCell::new_with_value(8, 8, 3);
let expected = Bint::new_with_value(8, 3);
assert_eq!(expected, Bint::from(&bint_cell));Source§impl From<DrainableBintCell> for Bint
impl From<DrainableBintCell> for Bint
Source§fn from(cell: DrainableBintCell) -> Self
fn from(cell: DrainableBintCell) -> Self
use bint::{Bint, DrainableBintCell};
let bint_cell = DrainableBintCell::new_with_value(8, 8, 3);
let expected = Bint::new_with_value(8, 3);
assert_eq!(expected, Bint::from(bint_cell));Source§impl Ord for Bint
impl Ord for Bint
Source§impl PartialOrd for Bint
impl PartialOrd for Bint
impl Copy for Bint
impl Eq for Bint
impl StructuralPartialEq for Bint
Auto Trait Implementations§
impl Freeze for Bint
impl RefUnwindSafe for Bint
impl Send for Bint
impl Sync for Bint
impl Unpin for Bint
impl UnwindSafe for Bint
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more