Skip to main content

TextCodedInteger

Struct TextCodedInteger 

Source
pub struct TextCodedInteger { /* private fields */ }
Expand description

A pedagogical integer type stored as decimal digits in a string.

All arithmetic is performed manually on the string representation, digit by digit. Values are kept in canonical form (no leading zeros, no -0), so equality is equality of values, and ordering compares values, not text.

Implementations§

Source§

impl TextCodedInteger

Source

pub fn new<T: ToString>(value: T) -> Self

Create a new TextCodedInteger from a string of decimal digits with an optional leading -, normalised (leading zeros removed, -0 becomes 0).

§Panics

Panics if the text is not of that form.

Source§

impl TextCodedInteger

Source

pub fn div_mod_manual(dividend: &Self, divisor: &Self) -> (Self, Self)

Manual long division: returns (quotient, remainder) Full manual long division: returns (quotient, remainder)

Trait Implementations§

Source§

impl Add for TextCodedInteger

Source§

type Output = TextCodedInteger

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl CheckedAdd for TextCodedInteger

Source§

fn checked_add(&self, rhs: &Self) -> Option<Self>

Adds two numbers, checking for overflow. If overflow happens, None is returned.
Source§

impl CheckedDiv for TextCodedInteger

Source§

fn checked_div(&self, rhs: &Self) -> Option<Self>

None for division by zero.

Source§

impl CheckedMul for TextCodedInteger

Source§

fn checked_mul(&self, rhs: &Self) -> Option<Self>

Never overflows: the digit string grows as needed.

Source§

impl CheckedSub for TextCodedInteger

Source§

fn checked_sub(&self, rhs: &Self) -> Option<Self>

Subtracts two numbers, checking for underflow. If underflow happens, None is returned.
Source§

impl Clone for TextCodedInteger

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for TextCodedInteger

Source§

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

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

impl Default for TextCodedInteger

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for TextCodedInteger

Source§

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

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

impl Div for TextCodedInteger

Source§

type Output = TextCodedInteger

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Self) -> Self::Output

Performs the / operation. Read more
Source§

impl Eq for TextCodedInteger

Source§

impl Mul for TextCodedInteger

Source§

type Output = TextCodedInteger

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl Neg for TextCodedInteger

Source§

type Output = TextCodedInteger

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl Num for TextCodedInteger

Source§

type FromStrRadixErr = ParseIntError

Source§

fn from_str_radix(s: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr>

Convert from a string and radix (typically 2..=36). Read more
Source§

impl One for TextCodedInteger

Source§

fn one() -> Self

Returns the multiplicative identity element of Self, 1. Read more
Source§

fn set_one(&mut self)

Sets self to the multiplicative identity element of Self, 1.
Source§

fn is_one(&self) -> bool
where Self: PartialEq,

Returns true if self is equal to the multiplicative identity. Read more
Source§

impl Ord for TextCodedInteger

Numeric order: by sign, then by magnitude (more digits is larger; equal lengths compare digit by digit), reversed for negative numbers.

Source§

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

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

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

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

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for TextCodedInteger

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialOrd for TextCodedInteger

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 Rem for TextCodedInteger

Source§

type Output = TextCodedInteger

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: Self) -> Self::Output

Performs the % operation. Read more
Source§

impl Signed for TextCodedInteger

Source§

fn abs_sub(&self, rhs: &Self) -> Self

The positive difference max(self − rhs, 0), as num_traits defines it.

Source§

fn abs(&self) -> Self

Computes the absolute value. Read more
Source§

fn signum(&self) -> Self

Returns the sign of the number. Read more
Source§

fn is_positive(&self) -> bool

Returns true if the number is positive and false if the number is zero or negative.
Source§

fn is_negative(&self) -> bool

Returns true if the number is negative and false if the number is zero or positive.
Source§

impl StructuralPartialEq for TextCodedInteger

Source§

impl Sub for TextCodedInteger

Source§

type Output = TextCodedInteger

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl Zero for TextCodedInteger

Source§

fn zero() -> Self

Returns the additive identity element of Self, 0. Read more
Source§

fn is_zero(&self) -> bool

Returns true if self is equal to the additive identity.
Source§

fn set_zero(&mut self)

Sets self to the additive identity element of Self, 0.

Auto Trait Implementations§

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, Rhs, Output> NumOps<Rhs, Output> for T
where T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.