Trait BigIntBuilder

Source
pub trait BigIntBuilder<const BASE: usize>
where Self: Debug,
{ // Required methods fn new() -> Self; fn push_front(&mut self, digit: Digit); fn push_back(&mut self, digit: Digit); fn is_empty(&self) -> bool; fn with_sign(self, sign: Sign) -> Self; }
Expand description

A builder for a big int. Use this to construct a big int one digit at a time, then call .into() to construct the final int.

You’re most likely better off using one of the From implementations as opposed to directly building your int via a builder.

use big_int::prelude::*;

let mut a = TightBuilder::<10>::new();
a.push_back(5);
a.push_back(3);
a.push_back(0);
a.push_back(4);
let a: Tight<10> = a.into();
assert_eq!(a, 5304.into());

Required Methods§

Source

fn new() -> Self

Create a new builder.

use big_int::prelude::*;

let mut a = TightBuilder::<10>::new();
unsafe {
    a.push_back(5);
}
let a: Tight<10> = a.into();
assert_eq!(a, 5.into());
Source

fn push_front(&mut self, digit: Digit)

Push a new digit to the end of the int.

use big_int::prelude::*;

let mut a = TightBuilder::<10>::new();
a.push_back(5);
a.push_back(6);
let a: Tight<10> = a.into();
assert_eq!(a, 56.into());
Source

fn push_back(&mut self, digit: Digit)

Push a new digit to the beginning of the int.

use big_int::prelude::*;

let mut a = TightBuilder::<10>::new();
a.push_front(5);
a.push_front(6);
let a: Tight<10> = a.into();
assert_eq!(a, 65.into());
Source

fn is_empty(&self) -> bool

Check if the builder is empty.

use big_int::prelude::*;

let mut a = TightBuilder::<10>::new();
assert!(a.is_empty());
a.push_front(5);
assert!(!a.is_empty());
Source

fn with_sign(self, sign: Sign) -> Self

The builder with the given sign.

use big_int::prelude::*;

let mut a = TightBuilder::<10>::new();
a.push_back(9);
let a: Tight<10> = a.with_sign(Negative).into();
assert_eq!(a, (-9).into());

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<const BASE: usize> BigIntBuilder<BASE> for LooseBuilder<BASE>

Source§

impl<const BASE: usize> BigIntBuilder<BASE> for LooseBytesBuilder<BASE>

Source§

impl<const BASE: usize> BigIntBuilder<BASE> for LooseShortsBuilder<BASE>

Source§

impl<const BASE: usize> BigIntBuilder<BASE> for LooseWordsBuilder<BASE>

Source§

impl<const BASE: usize> BigIntBuilder<BASE> for TightBuilder<BASE>

Source§

impl<const BASE: usize, B: BigIntBuilder<BASE>> BigIntBuilder<BASE> for DenormalBuilder<BASE, B>