pub trait Assign<T> {
// Required method
fn assign(&mut self, value: T);
}Expand description
Assign a value of type T to an integer.
One of the main benefits of assigning and reusing an Arbi integer is that
it can potentially avoid memory allocation if there’s already enough
capacity. In contrast, from methods typically involve memory allocation
(when the resulting integer is not zero).
§Examples
use arbi::{Arbi, Assign};
let mut a = Arbi::with_capacity(10);
let mut capacity = a.capacity();
// From integer
a.assign(u128::MAX);
assert_eq!(a, u128::MAX);
assert_eq!(a.capacity(), capacity); // no memory allocation occurred
// From float
a.assign(f64::MAX);
assert_eq!(a, f64::MAX);
assert!(a.capacity() > capacity); // memory allocation occured because we
// needed more capacity to represent the
// value
capacity = a.capacity();
// From string (no need for the Assign trait)
if let Err(e) = a.assign_str_radix("123456789", 10) {
panic!("Parsing error: {}", e);
}
assert_eq!(a, 123456789);
assert_eq!(a.capacity(), capacity); // no memory allocation occurred
// From another Arbi integer
let b = Arbi::from(987654321);
a.assign(&b);
assert_eq!(a.capacity(), capacity); // no memory allocation occurredRequired Methods§
Implementors§
impl Assign<&f64> for Arbi
impl Assign<&i8> for Arbi
impl Assign<&i16> for Arbi
impl Assign<&i32> for Arbi
impl Assign<&i64> for Arbi
impl Assign<&i128> for Arbi
impl Assign<&isize> for Arbi
impl Assign<&u8> for Arbi
impl Assign<&u16> for Arbi
impl Assign<&u32> for Arbi
impl Assign<&u64> for Arbi
impl Assign<&u128> for Arbi
impl Assign<&usize> for Arbi
impl Assign<&Arbi> for Arbi
Copies the contents of the argument Arbi integer into this Arbi integer.
If this Arbi integer already has enough capacity to represent value,
then no memory allocation occurs.