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.
Create a BigInteger
from string representation.
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");
- If the literal is empty.
- If invalid numeric characters are passed in the literal.
Create a BigInteger
from a slice of u8
digits.
Return true
if the integer value is positive, false
otherwise.
Return true
if the integer value is negative, false
otherwise.
Count the number of digits in the integer.
View the integer as a slice of the contained digits.
Return an iterator of digits from smallest unit to the largest
(right-to-left).
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);
Returns the number of elements the vector can hold without
reallocating.
let vec: Vec<i32> = Vec::with_capacity(10);
assert_eq!(vec.capacity(), 10);
Extracts a slice containing the entire vector.
Equivalent to &s[..]
.
use std::io::{self, Write};
let buffer = vec![1, 2, 3, 5, 8];
io::sink().write(buffer.as_slice()).unwrap();
Returns the number of elements in the vector, also referred to
as its 'length'.
let a = vec![1, 2, 3];
assert_eq!(a.len(), 3);
Returns true
if the vector contains no elements.
let mut v = Vec::new();
assert!(v.is_empty());
v.push(1);
assert!(!v.is_empty());
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
This method tests for self
and other
values to be equal, and is used by ==
. Read more
This method tests for !=
.
Performs copy-assignment from source
. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
The resulting type after dereferencing.
The resulting type after applying the +
operator.
Performs the +
operation.
The resulting type after applying the -
operator.
Performs the -
operation.
The resulting type after applying the *
operator.
Performs the *
operation.
The resulting type after applying the -
operator.
Performs the unary -
operation.
The resulting type after applying the <<
operator.
Performs the <<
operation.
The returned type after indexing.
Performs the indexing (container[index]
) operation.
Creates owned data from borrowed data, usually by cloning. Read more
🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String
. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static