[][src]Struct bigint_base10::BigInteger

pub struct BigInteger { /* fields omitted */ }

A type for arbitrarily-long representations of integer values.

This is helpful for representing integer values that are expected to exceed the largest representation possible with "plain-old-data" types, i.e. u64 / i64.

Usage is demonstrated in crate documentation.

Methods

impl BigInteger
[src]

pub fn new(literal: &str) -> BigInteger
[src]

Create a BigInteger from string representation.

Example

Requires a minimum of one digit to initialize a BigInteger. The value is assumed to be positive by default.

let my_int = BigInteger::new("1");

assert_eq!(format!("{}", my_int), "+1");

A sign can be specified.

let my_int = BigInteger::new("-1");

assert_eq!(format!("{}", my_int), "-1");

Zero has no sign. Any provided signs are discarded.

let my_int = BigInteger::new("-0");

assert_eq!(format!("{}", my_int), "0");

Panics

  • If the literal is empty.
  • If invalid numeric characters are passed in the literal.

pub fn from_digits(digits: &[u8], sign: Sign) -> BigInteger
[src]

Create a BigInteger from a slice of u8 digits.

pub fn is_positive(&self) -> bool
[src]

Return true if the integer value is positive, false otherwise.

pub fn is_negative(&self) -> bool
[src]

Return true if the integer value is negative, false otherwise.

pub fn count(&self) -> usize
[src]

Count the number of digits in the integer.

pub fn as_slice(&self) -> &[u8]
[src]

View the integer as a slice of the contained digits.

pub fn digits(
    &self
) -> impl Iterator<Item = u8> + DoubleEndedIterator + '_
[src]

Return an iterator of digits from smallest unit to the largest (right-to-left).

Example

Usage.

let my_int = BigInteger::new("123");

let mut iter = my_int.digits();

assert_eq!(iter.next(), Some(3));
assert_eq!(iter.next(), Some(2));
assert_eq!(iter.next(), Some(1));
assert_eq!(iter.next(), None);

Methods from Deref<Target = Vec<u8>>

pub fn capacity(&self) -> usize
1.0.0
[src]

Returns the number of elements the vector can hold without reallocating.

Examples

let vec: Vec<i32> = Vec::with_capacity(10);
assert_eq!(vec.capacity(), 10);

pub fn as_slice(&self) -> &[T]
1.7.0
[src]

Extracts a slice containing the entire vector.

Equivalent to &s[..].

Examples

use std::io::{self, Write};
let buffer = vec![1, 2, 3, 5, 8];
io::sink().write(buffer.as_slice()).unwrap();

pub fn len(&self) -> usize
1.0.0
[src]

Returns the number of elements in the vector, also referred to as its 'length'.

Examples

let a = vec![1, 2, 3];
assert_eq!(a.len(), 3);

pub fn is_empty(&self) -> bool
1.0.0
[src]

Returns true if the vector contains no elements.

Examples

let mut v = Vec::new();
assert!(v.is_empty());

v.push(1);
assert!(!v.is_empty());

Trait Implementations

impl PartialOrd<BigInteger> for BigInteger
[src]

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl PartialEq<BigInteger> for BigInteger
[src]

impl Clone for BigInteger
[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl Debug for BigInteger
[src]

impl Display for BigInteger
[src]

impl Deref for BigInteger
[src]

type Target = Vec<u8>

The resulting type after dereferencing.

impl<'a> Add<&'a BigInteger> for BigInteger
[src]

type Output = Self

The resulting type after applying the + operator.

impl<'a> Sub<&'a BigInteger> for BigInteger
[src]

type Output = Self

The resulting type after applying the - operator.

impl<'a> Mul<&'a BigInteger> for BigInteger
[src]

type Output = Self

The resulting type after applying the * operator.

impl Neg for BigInteger
[src]

type Output = BigInteger

The resulting type after applying the - operator.

impl Shl<usize> for BigInteger
[src]

type Output = Self

The resulting type after applying the << operator.

impl Index<usize> for BigInteger
[src]

type Output = u8

The returned type after indexing.

Auto Trait Implementations

impl Send for BigInteger

impl Sync for BigInteger

Blanket Implementations

impl<T> From for T
[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]