Bint

Struct Bint 

Source
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: u8

Implementations§

Source§

impl Bint

Source

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);
Examples found in repository?
examples/double.rs (line 8)
7fn main() {
8    let mut bint = Bint::new(30);
9    for _ in 0..60 {
10        let (x, y) = perms(bint.value);
11        bint = bint.up();
12        println!("{} {}", x, y);
13    }
14}
Source

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);
Source

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);
Examples found in repository?
examples/double.rs (line 11)
7fn main() {
8    let mut bint = Bint::new(30);
9    for _ in 0..60 {
10        let (x, y) = perms(bint.value);
11        bint = bint.up();
12        println!("{} {}", x, y);
13    }
14}
Source

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);
Source

pub fn down(&self) -> Bint

use bint::Bint;

let b: Bint = Bint {
    value: 1,
    boundary: 6,
};

let b: Bint = b.down();
assert_eq!(0, b.value);

let b: Bint = b.down();
assert_eq!(5, b.value);
Source

pub fn down_x(self, x: u8) -> Bint

use bint::Bint;

let b: Bint = Bint {
    value: 4,
    boundary: 6,
};

let b: Bint = b.down_x(6);
assert_eq!(4, b.value);

let b: Bint = b.down_x(3);
assert_eq!(1, b.value);

Trait Implementations§

Source§

impl Clone for Bint

Source§

fn clone(&self) -> Bint

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Bint

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Bint

Source§

fn default() -> Self

Defaults to the maximum value of an unsigned 8 integer.

use bint::Bint;

let mut b = Bint::default();

for _ in 0..u8::MAX {
    b = b.down()
}

for _ in 0..u8::MAX {
    b = b.down()
}

assert_eq!(b.value, 0)
Source§

impl Display for Bint

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<&Bint> for BintCell

Source§

fn from(cell: &Bint) -> Self

use bint::{Bint, BintCell};

let bint = Bint::new_with_value(8, 3);
let expected = BintCell::new_with_value(8, 3);

assert_eq!(expected, BintCell::from(&bint));
Source§

impl From<&BintCell> for Bint

Source§

fn from(cell: &BintCell) -> Self

use bint::{Bint, BintCell};

let cell = BintCell::new_with_value(8, 3);
let expected = Bint {
    value: cell.value(),
    boundary: cell.boundary,
};

assert_eq!(expected, Bint::from(cell));
Source§

impl From<&DrainableBintCell> for Bint

Source§

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<Bint> for BintCell

Source§

fn from(cell: Bint) -> Self

use bint::{Bint, BintCell};

let bint = Bint::new_with_value(8, 3);
let expected = BintCell::new_with_value(8, 3);

assert_eq!(expected, BintCell::from(bint));
Source§

impl From<BintCell> for Bint

Source§

fn from(cell: BintCell) -> Self

use bint::{Bint, BintCell};

let cell = BintCell::new_with_value(8, 3);
let expected = Bint {
    value: cell.value(),
    boundary: cell.boundary,
};

assert_eq!(expected, Bint::from(cell));
Source§

impl From<DrainableBintCell> for Bint

Source§

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 Hash for Bint

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Bint

Source§

fn cmp(&self, other: &Bint) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Bint

Source§

fn eq(&self, other: &Bint) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Bint

Source§

fn partial_cmp(&self, other: &Bint) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for Bint

Source§

impl Eq for Bint

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.