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 .build() to finalize the builder.

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.build();
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();
a.push_back(5);
assert_eq!(a.build(), 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);
assert_eq!(a.build(), 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);
assert_eq!(a.build(), 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);
assert_eq!(a.with_sign(Negative).build(), (-9).into());

Object Safety§

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 TightBuilder<BASE>