Struct malachite_nz::natural::conversion::string::to_string::BaseFmtWrapper
source · pub struct BaseFmtWrapper<T> { /* private fields */ }
Expand description
Implementations§
source§impl<T> BaseFmtWrapper<T>
impl<T> BaseFmtWrapper<T>
sourcepub fn new(x: T, base: u8) -> Self
pub fn new(x: T, base: u8) -> Self
Creates a new BaseFmtWrapper
.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if base
is less than 2 or greater than 36.
§Examples
use malachite_nz::integer::Integer;
use malachite_nz::natural::conversion::string::to_string::BaseFmtWrapper;
use malachite_nz::natural::Natural;
let n = Natural::from(1000000000u32);
let x = BaseFmtWrapper::new(&n, 36);
assert_eq!(format!("{}", x), "gjdgxs");
assert_eq!(format!("{:#}", x), "GJDGXS");
let n = Integer::from(-1000000000);
let x = BaseFmtWrapper::new(&n, 36);
assert_eq!(format!("{}", x), "-gjdgxs");
assert_eq!(format!("{:#}", x), "-GJDGXS");
sourcepub fn unwrap(self) -> T
pub fn unwrap(self) -> T
Recovers the value from a BaseFmtWrapper
.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_nz::natural::conversion::string::to_string::BaseFmtWrapper;
use malachite_nz::natural::Natural;
assert_eq!(
BaseFmtWrapper::new(Natural::from(1000000000u32), 36).unwrap(),
1000000000
);
Trait Implementations§
source§impl<T: Clone> Clone for BaseFmtWrapper<T>
impl<T: Clone> Clone for BaseFmtWrapper<T>
source§fn clone(&self) -> BaseFmtWrapper<T>
fn clone(&self) -> BaseFmtWrapper<T>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<'a> Debug for BaseFmtWrapper<&'a Integer>
impl<'a> Debug for BaseFmtWrapper<&'a Integer>
source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Writes a wrapped Integer
to a string using a specified base.
If the base is greater than 10, lowercase alphabetic letters are used by default. Using the
#
flag switches to uppercase letters. Padding with zeros works as usual.
This is the same as the Display::fmt
implementation.
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if base
is less than 2 or greater than 36.
§Examples
use malachite_nz::integer::Integer;
use malachite_nz::natural::conversion::string::to_string::BaseFmtWrapper;
let n = Integer::from(-1000000000);
let x = BaseFmtWrapper::new(&n, 36);
assert_eq!(format!("{:?}", x), "-gjdgxs");
assert_eq!(format!("{:#?}", x), "-GJDGXS");
assert_eq!(format!("{:010?}", x), "-000gjdgxs");
assert_eq!(format!("{:#010?}", x), "-000GJDGXS");
source§impl<'a> Debug for BaseFmtWrapper<&'a Natural>
impl<'a> Debug for BaseFmtWrapper<&'a Natural>
source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Writes a wrapped Natural
to a string using a specified base.
If the base is greater than 10, lowercase alphabetic letters are used by default. Using the
#
flag switches to uppercase letters. Padding with zeros works as usual.
This is the same as the Display::fmt
implementation.
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if base
is less than 2 or greater than 36.
§Examples
use malachite_nz::natural::conversion::string::to_string::BaseFmtWrapper;
use malachite_nz::natural::Natural;
let n = Natural::from(1000000000u32);
let x = BaseFmtWrapper::new(&n, 36);
assert_eq!(format!("{:?}", x), "gjdgxs");
assert_eq!(format!("{:#?}", x), "GJDGXS");
assert_eq!(format!("{:010?}", x), "0000gjdgxs");
assert_eq!(format!("{:#010?}", x), "0000GJDGXS");
source§impl<'a> Display for BaseFmtWrapper<&'a Integer>
impl<'a> Display for BaseFmtWrapper<&'a Integer>
source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Writes a wrapped Integer
to a string using a specified base.
If the base is greater than 10, lowercase alphabetic letters are used by default. Using the
#
flag switches to uppercase letters. Padding with zeros works as usual.
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if base
is less than 2 or greater than 36.
§Examples
use malachite_nz::integer::Integer;
use malachite_nz::natural::conversion::string::to_string::BaseFmtWrapper;
let n = Integer::from(-1000000000);
let x = BaseFmtWrapper::new(&n, 36);
assert_eq!(format!("{}", x), "-gjdgxs");
assert_eq!(format!("{:#}", x), "-GJDGXS");
assert_eq!(format!("{:010}", x), "-000gjdgxs");
assert_eq!(format!("{:#010}", x), "-000GJDGXS");
source§impl<'a> Display for BaseFmtWrapper<&'a Natural>
impl<'a> Display for BaseFmtWrapper<&'a Natural>
source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Writes a wrapped Natural
to a string using a specified base.
If the base is greater than 10, lowercase alphabetic letters are used by default. Using the
#
flag switches to uppercase letters. Padding with zeros works as usual.
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if base
is less than 2 or greater than 36.
§Examples
use malachite_nz::natural::conversion::string::to_string::BaseFmtWrapper;
use malachite_nz::natural::Natural;
let n = Natural::from(1000000000u32);
let x = BaseFmtWrapper::new(&n, 36);
assert_eq!(format!("{}", x), "gjdgxs");
assert_eq!(format!("{:#}", x), "GJDGXS");
assert_eq!(format!("{:010}", x), "0000gjdgxs");
assert_eq!(format!("{:#010}", x), "0000GJDGXS");
source§impl<T: Hash> Hash for BaseFmtWrapper<T>
impl<T: Hash> Hash for BaseFmtWrapper<T>
source§impl<T: PartialEq> PartialEq for BaseFmtWrapper<T>
impl<T: PartialEq> PartialEq for BaseFmtWrapper<T>
source§fn eq(&self, other: &BaseFmtWrapper<T>) -> bool
fn eq(&self, other: &BaseFmtWrapper<T>) -> bool
self
and other
values to be equal, and is used
by ==
.