pub struct StringRadix { /* private fields */ }
Expand description
Radix number, that is usually written as numberbase (4448 for
example), but number is represented as String
so base could be from range 2..=36
.
Implementations§
Source§impl StringRadix
impl StringRadix
Sourcepub fn new(base: u8) -> Result<Self, RadixError>
pub fn new(base: u8) -> Result<Self, RadixError>
Creates a new StringRadix
.
§Errors
Returns a BaseError
when base isn’t correct.
§Examples
use ognlib::num::radix::StringRadix;
let n = StringRadix::new(2).unwrap();
assert_eq!(n.number(), "0");
assert_eq!(n.base(), 2);
let e1 = StringRadix::new(1).unwrap_err();
assert_eq!(e1.to_string(), "Expected base in range `2..=36`, found 1");
let e2 = StringRadix::new(255).unwrap_err();
assert_eq!(e2.to_string(), "Expected base in range `2..=36`, found 255");
Sourcepub fn from_radix(number: &str, base: u8) -> Result<Self, RadixError>
pub fn from_radix(number: &str, base: u8) -> Result<Self, RadixError>
Creates a new StringRadix
with given str
number and base.
§Errors
Returns a BaseError
when base isn’t correct or NumberError
when number contains
digit that are more or equal than base.
§Examples
use ognlib::num::radix::StringRadix;
let n = StringRadix::from_radix("11010000", 2).unwrap();
assert_eq!(n.number(), "11010000");
assert_eq!(n.base(), 2);
let e = StringRadix::from_radix("129", 9).unwrap_err();
assert_eq!(e.to_string(), "Number contains a digit (9) that is more or equal than base (9)",);
Sourcepub fn number(&self) -> &str
pub fn number(&self) -> &str
Returns a number of StringRadix
.
§Example
use ognlib::num::radix::StringRadix;
let radix = StringRadix::from_radix("444", 5).unwrap();
assert_eq!(radix.number(), "444");
Sourcepub const fn base(&self) -> u8
pub const fn base(&self) -> u8
Returns a base of StringRadix
.
§Example
use ognlib::num::radix::StringRadix;
let radix = StringRadix::from_radix("444", 5).unwrap();
assert_eq!(radix.base(), 5);
Sourcepub fn radix(&self) -> (&str, u8)
pub fn radix(&self) -> (&str, u8)
Returns a full StringRadix
as tuple (number, base)
.
§Example
use ognlib::num::radix::StringRadix;
let radix = StringRadix::from_radix("444", 5).unwrap();
assert_eq!(radix.radix(), ("444", 5));
Sourcepub fn to_radix(&mut self, base: u8) -> Result<Self, RadixError>
pub fn to_radix(&mut self, base: u8) -> Result<Self, RadixError>
Translate StringRadix
to another StringRadix
.
§Panics
Panics if k is less than 2 or k more than 36.
§Errors
Returns a BaseError
when base isn’t correct; ParseError
if there was error with
parse functions.
§Examples
use ognlib::num::radix::StringRadix;
let mut n = StringRadix::from_radix("11010000", 2).unwrap();
let mut res = n.to_radix(16).unwrap();
assert_eq!(res.radix(), ("D0", 16));
let e = res.to_radix(42).unwrap_err();
assert_eq!(e.to_string(), "Expected base in range `2..=36`, found 42");
Sourcepub fn to_int_radix(&mut self, base: u8) -> Result<Radix, RadixError>
pub fn to_int_radix(&mut self, base: u8) -> Result<Radix, RadixError>
Translate StringRadix
to another Radix
.
§Panics
Panics if k is less than 2 or k more than 36.
§Errors
Returns a BaseError
when base isn’t correct; ParseError
if there was error with
parse functions.
§Examples
use ognlib::num::radix::{Radix, StringRadix};
let mut n = StringRadix::from_radix("D14", 16).unwrap();
let res = n.to_int_radix(2).unwrap();
assert_eq!(res.radix(), (110100010100, 2));
let e = n.to_int_radix(12).unwrap_err();
assert_eq!(e.to_string(), "Expected base in range `2..=10`, found 12");
Sourcepub fn add_to_int(self, other: Self, base: u8) -> Result<Radix, RadixError>
pub fn add_to_int(self, other: Self, base: u8) -> Result<Radix, RadixError>
Sum 2 StringRadix
to new Radix
.
§Errors
Same as to_int_radix
.
§Examples
use ognlib::num::radix::{Radix, StringRadix};
let n1 = StringRadix::from_radix("123", 4).unwrap();
let n2 = StringRadix::from_radix("444", 5).unwrap();
let res = StringRadix::add_to_int(n1, n2, 8).unwrap();
assert_eq!(res.radix(), (227, 8));
Sourcepub fn sub_to_int(self, other: Self, base: u8) -> Result<Radix, RadixError>
pub fn sub_to_int(self, other: Self, base: u8) -> Result<Radix, RadixError>
Sub 2 StringRadix
to new Radix
.
§Errors
Same as to_int_radix
.
§Examples
use ognlib::num::radix::{Radix, StringRadix};
let n1 = StringRadix::from_radix("123", 4).unwrap();
let n2 = StringRadix::from_radix("444", 5).unwrap();
let res = StringRadix::sub_to_int(n2, n1, 8).unwrap();
assert_eq!(res.radix(), (141, 8));
Sourcepub fn mul_to_int(self, other: Self, base: u8) -> Result<Radix, RadixError>
pub fn mul_to_int(self, other: Self, base: u8) -> Result<Radix, RadixError>
Mul 2 StringRadix
to new Radix
.
§Errors
Same as to_int_radix
.
§Examples
use ognlib::num::radix::{Radix, StringRadix};
let n1 = StringRadix::from_radix("123", 4).unwrap();
let n2 = StringRadix::from_radix("444", 5).unwrap();
let res = StringRadix::mul_to_int(n1, n2, 8).unwrap();
assert_eq!(res.radix(), (6424, 8));
Trait Implementations§
Source§impl Add<usize> for StringRadix
impl Add<usize> for StringRadix
Source§fn add(self, other: usize) -> Self::Output
fn add(self, other: usize) -> Self::Output
Performs a +
operation (usize
as rhs
).
§Examples
use ognlib::num::radix::{Radix, StringRadix};
let n = Radix::from_radix(123, 4).unwrap();
let n_str = StringRadix::from_radix("123", 4).unwrap();
let res = (n + 124).to_radix(8).unwrap();
let res_str = (n_str + 124).to_radix(8).unwrap();
assert_eq!(res.radix(), (227, 8));
assert_eq!(res_str.radix(), ("227", 8));
Source§type Output = StringRadix
type Output = StringRadix
+
operator.Source§impl Add for StringRadix
impl Add for StringRadix
Source§fn add(self, other: Self) -> Self::Output
fn add(self, other: Self) -> Self::Output
Performs a +
operation.
§Examples
use ognlib::num::radix::{Radix, StringRadix};
let n1 = Radix::from_radix(123, 4).unwrap();
let n2 = Radix::from_radix(444, 5).unwrap();
let n_str1 = StringRadix::from_radix("123", 4).unwrap();
let n_str2 = StringRadix::from_radix("444", 5).unwrap();
let res = (n1 + n2).to_radix(8).unwrap();
let res_str = (n_str1 + n_str2).to_radix(8).unwrap();
assert_eq!(res.radix(), (227, 8));
assert_eq!(res_str.radix(), ("227", 8));
Source§type Output = StringRadix
type Output = StringRadix
+
operator.Source§impl AddAssign<usize> for StringRadix
impl AddAssign<usize> for StringRadix
Source§fn add_assign(&mut self, other: usize)
fn add_assign(&mut self, other: usize)
Performs a +=
operation (usize
is rhs).
§Examples
use ognlib::num::radix::{Radix, StringRadix};
let mut n = Radix::from_radix(123, 4).unwrap();
let mut n_str = StringRadix::from_radix("123", 4).unwrap();
n += 124;
n_str += 124;
n = n.to_radix(8).unwrap();
n_str = n_str.to_radix(8).unwrap();
assert_eq!(n.radix(), (227, 8));
assert_eq!(n_str.radix(), ("227", 8));
Source§impl AddAssign for StringRadix
impl AddAssign for StringRadix
Source§fn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
Performs a +=
operation.
§Examples
use ognlib::num::radix::{Radix, StringRadix};
let mut n1 = Radix::from_radix(123, 4).unwrap();
let n2 = Radix::from_radix(444, 5).unwrap();
let mut n_str1 = StringRadix::from_radix("123", 4).unwrap();
let n_str2 = StringRadix::from_radix("444", 5).unwrap();
n1 += n2;
n_str1 += n_str2;
n1 = n1.to_radix(8).unwrap();
n_str1 = n_str1.to_radix(8).unwrap();
assert_eq!(n1.radix(), (227, 8));
assert_eq!(n_str1.radix(), ("227", 8));
Source§impl Clone for StringRadix
impl Clone for StringRadix
Source§fn clone(&self) -> StringRadix
fn clone(&self) -> StringRadix
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for StringRadix
impl Debug for StringRadix
Source§impl Div<usize> for StringRadix
impl Div<usize> for StringRadix
Source§fn div(self, other: usize) -> Self::Output
fn div(self, other: usize) -> Self::Output
Performs a /
operation (usize
as rhs).
§Examples
use ognlib::num::radix::{Radix, StringRadix};
let n = Radix::from_radix(444, 5).unwrap();
let n_str = StringRadix::from_radix("444", 5).unwrap();
let res = (n / 27).to_radix(8).unwrap();
let res_str = (n_str / 27).to_radix(8).unwrap();
assert_eq!(res.radix(), (4, 8));
assert_eq!(res_str.radix(), ("4", 8));
Source§type Output = StringRadix
type Output = StringRadix
/
operator.Source§impl Div for StringRadix
impl Div for StringRadix
Source§fn div(self, other: Self) -> Self::Output
fn div(self, other: Self) -> Self::Output
Performs a /
operation.
§Examples
use ognlib::num::radix::{Radix, StringRadix};
let n1 = Radix::from_radix(123, 4).unwrap();
let n2 = Radix::from_radix(444, 5).unwrap();
let n_str1 = StringRadix::from_radix("123", 4).unwrap();
let n_str2 = StringRadix::from_radix("444", 5).unwrap();
let res = (n2 / n1).to_radix(8).unwrap();
let res_str = (n_str2 / n_str1).to_radix(8).unwrap();
assert_eq!(res.radix(), (4, 8));
assert_eq!(res_str.radix(), ("4", 8));
Source§type Output = StringRadix
type Output = StringRadix
/
operator.Source§impl DivAssign<usize> for StringRadix
impl DivAssign<usize> for StringRadix
Source§fn div_assign(&mut self, other: usize)
fn div_assign(&mut self, other: usize)
Performs a /=
operation (usize
as rhs).
§Examples
use ognlib::num::radix::{Radix, StringRadix};
let mut n = Radix::from_radix(444, 5).unwrap();
let mut n_str = StringRadix::from_radix("444", 5).unwrap();
n /= 27;
n_str /= 27;
n = n.to_radix(8).unwrap();
n_str = n_str.to_radix(8).unwrap();
assert_eq!(n.radix(), (4, 8));
assert_eq!(n_str.radix(), ("4", 8));
Source§impl DivAssign for StringRadix
impl DivAssign for StringRadix
Source§fn div_assign(&mut self, other: Self)
fn div_assign(&mut self, other: Self)
Performs a /=
operation.
§Examples
use ognlib::num::radix::{Radix, StringRadix};
let n1 = Radix::from_radix(123, 4).unwrap();
let mut n2 = Radix::from_radix(444, 5).unwrap();
let n_str1 = StringRadix::from_radix("123", 4).unwrap();
let mut n_str2 = StringRadix::from_radix("444", 5).unwrap();
n2 /= n1;
n_str2 /= n_str1;
n2 = n2.to_radix(8).unwrap();
n_str2 = n_str2.to_radix(8).unwrap();
assert_eq!(n2.radix(), (4, 8));
assert_eq!(n_str2.radix(), ("4", 8));
Source§impl From<&StringRadix> for i16
impl From<&StringRadix> for i16
Source§fn from(radix: &StringRadix) -> Self
fn from(radix: &StringRadix) -> Self
Converts a StringRadix
into primitive int.
§Example
use ognlib::num::radix::StringRadix;
let radix = StringRadix::from_radix("444", 5).unwrap();
let num: i16 = radix.into();
assert_eq!(num, 124i16);
Source§impl From<&StringRadix> for i32
impl From<&StringRadix> for i32
Source§fn from(radix: &StringRadix) -> Self
fn from(radix: &StringRadix) -> Self
Converts a StringRadix
into primitive int.
§Example
use ognlib::num::radix::StringRadix;
let radix = StringRadix::from_radix("444", 5).unwrap();
let num: i32 = radix.into();
assert_eq!(num, 124i32);
Source§impl From<&StringRadix> for i64
impl From<&StringRadix> for i64
Source§fn from(radix: &StringRadix) -> Self
fn from(radix: &StringRadix) -> Self
Converts a StringRadix
into primitive int.
§Example
use ognlib::num::radix::StringRadix;
let radix = StringRadix::from_radix("444", 5).unwrap();
let num: i64 = radix.into();
assert_eq!(num, 124i64);
Source§impl From<&StringRadix> for i8
impl From<&StringRadix> for i8
Source§fn from(radix: &StringRadix) -> Self
fn from(radix: &StringRadix) -> Self
Converts a StringRadix
into primitive int.
§Example
use ognlib::num::radix::StringRadix;
let radix = StringRadix::from_radix("444", 5).unwrap();
let num: i8 = radix.into();
assert_eq!(num, 124i8);
Source§impl From<&StringRadix> for isize
impl From<&StringRadix> for isize
Source§fn from(radix: &StringRadix) -> Self
fn from(radix: &StringRadix) -> Self
Converts a StringRadix
into primitive int.
§Example
use ognlib::num::radix::StringRadix;
let radix = StringRadix::from_radix("444", 5).unwrap();
let num: isize = radix.into();
assert_eq!(num, 124isize);
Source§impl From<&StringRadix> for u16
impl From<&StringRadix> for u16
Source§fn from(radix: &StringRadix) -> Self
fn from(radix: &StringRadix) -> Self
Converts a StringRadix
into primitive int.
§Example
use ognlib::num::radix::StringRadix;
let radix = StringRadix::from_radix("444", 5).unwrap();
let num: u16 = radix.into();
assert_eq!(num, 124u16);
Source§impl From<&StringRadix> for u32
impl From<&StringRadix> for u32
Source§fn from(radix: &StringRadix) -> Self
fn from(radix: &StringRadix) -> Self
Converts a StringRadix
into primitive int.
§Example
use ognlib::num::radix::StringRadix;
let radix = StringRadix::from_radix("444", 5).unwrap();
let num: u32 = radix.into();
assert_eq!(num, 124u32);
Source§impl From<&StringRadix> for u64
impl From<&StringRadix> for u64
Source§fn from(radix: &StringRadix) -> Self
fn from(radix: &StringRadix) -> Self
Converts a StringRadix
into primitive int.
§Example
use ognlib::num::radix::StringRadix;
let radix = StringRadix::from_radix("444", 5).unwrap();
let num: u64 = radix.into();
assert_eq!(num, 124u64);
Source§impl From<&StringRadix> for u8
impl From<&StringRadix> for u8
Source§fn from(radix: &StringRadix) -> Self
fn from(radix: &StringRadix) -> Self
Converts a StringRadix
into primitive int.
§Example
use ognlib::num::radix::StringRadix;
let radix = StringRadix::from_radix("444", 5).unwrap();
let num: u8 = radix.into();
assert_eq!(num, 124u8);
Source§impl From<&StringRadix> for usize
impl From<&StringRadix> for usize
Source§fn from(radix: &StringRadix) -> Self
fn from(radix: &StringRadix) -> Self
Converts a StringRadix
into primitive int.
§Example
use ognlib::num::radix::StringRadix;
let radix = StringRadix::from_radix("444", 5).unwrap();
let num: usize = radix.into();
assert_eq!(num, 124usize);
Source§impl From<StringRadix> for i16
impl From<StringRadix> for i16
Source§fn from(radix: StringRadix) -> Self
fn from(radix: StringRadix) -> Self
Converts a StringRadix
into primitive int.
§Example
use ognlib::num::radix::StringRadix;
let radix = StringRadix::from_radix("444", 5).unwrap();
let num: usize = radix.into();
assert_eq!(num, 124);
Source§impl From<StringRadix> for i32
impl From<StringRadix> for i32
Source§fn from(radix: StringRadix) -> Self
fn from(radix: StringRadix) -> Self
Converts a StringRadix
into primitive int.
§Example
use ognlib::num::radix::StringRadix;
let radix = StringRadix::from_radix("444", 5).unwrap();
let num: usize = radix.into();
assert_eq!(num, 124);
Source§impl From<StringRadix> for i64
impl From<StringRadix> for i64
Source§fn from(radix: StringRadix) -> Self
fn from(radix: StringRadix) -> Self
Converts a StringRadix
into primitive int.
§Example
use ognlib::num::radix::StringRadix;
let radix = StringRadix::from_radix("444", 5).unwrap();
let num: usize = radix.into();
assert_eq!(num, 124);
Source§impl From<StringRadix> for i8
impl From<StringRadix> for i8
Source§fn from(radix: StringRadix) -> Self
fn from(radix: StringRadix) -> Self
Converts a StringRadix
into primitive int.
§Example
use ognlib::num::radix::StringRadix;
let radix = StringRadix::from_radix("444", 5).unwrap();
let num: usize = radix.into();
assert_eq!(num, 124);
Source§impl From<StringRadix> for isize
impl From<StringRadix> for isize
Source§fn from(radix: StringRadix) -> Self
fn from(radix: StringRadix) -> Self
Converts a StringRadix
into primitive int.
§Example
use ognlib::num::radix::StringRadix;
let radix = StringRadix::from_radix("444", 5).unwrap();
let num: usize = radix.into();
assert_eq!(num, 124);
Source§impl From<StringRadix> for u16
impl From<StringRadix> for u16
Source§fn from(radix: StringRadix) -> Self
fn from(radix: StringRadix) -> Self
Converts a StringRadix
into primitive int.
§Example
use ognlib::num::radix::StringRadix;
let radix = StringRadix::from_radix("444", 5).unwrap();
let num: usize = radix.into();
assert_eq!(num, 124);
Source§impl From<StringRadix> for u32
impl From<StringRadix> for u32
Source§fn from(radix: StringRadix) -> Self
fn from(radix: StringRadix) -> Self
Converts a StringRadix
into primitive int.
§Example
use ognlib::num::radix::StringRadix;
let radix = StringRadix::from_radix("444", 5).unwrap();
let num: usize = radix.into();
assert_eq!(num, 124);
Source§impl From<StringRadix> for u64
impl From<StringRadix> for u64
Source§fn from(radix: StringRadix) -> Self
fn from(radix: StringRadix) -> Self
Converts a StringRadix
into primitive int.
§Example
use ognlib::num::radix::StringRadix;
let radix = StringRadix::from_radix("444", 5).unwrap();
let num: usize = radix.into();
assert_eq!(num, 124);
Source§impl From<StringRadix> for u8
impl From<StringRadix> for u8
Source§fn from(radix: StringRadix) -> Self
fn from(radix: StringRadix) -> Self
Converts a StringRadix
into primitive int.
§Example
use ognlib::num::radix::StringRadix;
let radix = StringRadix::from_radix("444", 5).unwrap();
let num: usize = radix.into();
assert_eq!(num, 124);
Source§impl From<StringRadix> for usize
impl From<StringRadix> for usize
Source§fn from(radix: StringRadix) -> Self
fn from(radix: StringRadix) -> Self
Converts a StringRadix
into primitive int.
§Example
use ognlib::num::radix::StringRadix;
let radix = StringRadix::from_radix("444", 5).unwrap();
let num: usize = radix.into();
assert_eq!(num, 124);
Source§impl From<i16> for StringRadix
impl From<i16> for StringRadix
Source§impl From<i32> for StringRadix
impl From<i32> for StringRadix
Source§impl From<i64> for StringRadix
impl From<i64> for StringRadix
Source§impl From<i8> for StringRadix
impl From<i8> for StringRadix
Source§impl From<isize> for StringRadix
impl From<isize> for StringRadix
Source§impl From<u16> for StringRadix
impl From<u16> for StringRadix
Source§impl From<u32> for StringRadix
impl From<u32> for StringRadix
Source§impl From<u64> for StringRadix
impl From<u64> for StringRadix
Source§impl From<u8> for StringRadix
impl From<u8> for StringRadix
Source§impl From<usize> for StringRadix
impl From<usize> for StringRadix
Source§impl FromStr for StringRadix
impl FromStr for StringRadix
Source§fn from_str(number: &str) -> Result<Self, Self::Err>
fn from_str(number: &str) -> Result<Self, Self::Err>
Creates a new StringRadix
with base 10 and given str
number.
§Errors
Returns ParseIntError
if number contains invalid digit.
§Examples
use {core::str::FromStr, ognlib::num::radix::StringRadix};
let n = StringRadix::from_str("123").unwrap();
assert_eq!(n.radix(), ("123", 10));
let e = StringRadix::from_str("12A").unwrap_err();
assert_eq!(e.to_string(), "invalid digit found in string");
Source§type Err = ParseIntError
type Err = ParseIntError
Source§impl Mul<usize> for StringRadix
impl Mul<usize> for StringRadix
Source§fn mul(self, other: usize) -> Self::Output
fn mul(self, other: usize) -> Self::Output
Performs a *
operation (usize
as rhs).
§Examples
use ognlib::num::radix::{Radix, StringRadix};
let n = Radix::from_radix(123, 4).unwrap();
let n_str = StringRadix::from_radix("123", 4).unwrap();
let res = (n * 124).to_radix(8).unwrap();
let res_str = (n_str * 124).to_radix(8).unwrap();
assert_eq!(res.radix(), (6424, 8));
assert_eq!(res_str.radix(), ("6424", 8));
Source§type Output = StringRadix
type Output = StringRadix
*
operator.Source§impl Mul for StringRadix
impl Mul for StringRadix
Source§fn mul(self, other: Self) -> Self::Output
fn mul(self, other: Self) -> Self::Output
Performs a *
operation.
§Examples
use ognlib::num::radix::{Radix, StringRadix};
let n1 = Radix::from_radix(123, 4).unwrap();
let n2 = Radix::from_radix(444, 5).unwrap();
let n_str1 = StringRadix::from_radix("123", 4).unwrap();
let n_str2 = StringRadix::from_radix("444", 5).unwrap();
let res = (n1 * n2).to_radix(8).unwrap();
let res_str = (n_str1 * n_str2).to_radix(8).unwrap();
assert_eq!(res.radix(), (6424, 8));
assert_eq!(res_str.radix(), ("6424", 8));
Source§type Output = StringRadix
type Output = StringRadix
*
operator.Source§impl MulAssign<usize> for StringRadix
impl MulAssign<usize> for StringRadix
Source§fn mul_assign(&mut self, other: usize)
fn mul_assign(&mut self, other: usize)
Performs a *=
operation (usize
as rhs).
§Examples
use ognlib::num::radix::{Radix, StringRadix};
let mut n = Radix::from_radix(123, 4).unwrap();
let mut n_str = StringRadix::from_radix("123", 4).unwrap();
n *= 124;
n_str *= 124;
n = n.to_radix(8).unwrap();
n_str = n_str.to_radix(8).unwrap();
assert_eq!(n.radix(), (6424, 8));
assert_eq!(n_str.radix(), ("6424", 8));
Source§impl MulAssign for StringRadix
impl MulAssign for StringRadix
Source§fn mul_assign(&mut self, other: Self)
fn mul_assign(&mut self, other: Self)
Performs a *=
operation.
§Examples
use ognlib::num::radix::{Radix, StringRadix};
let mut n1 = Radix::from_radix(123, 4).unwrap();
let n2 = Radix::from_radix(444, 5).unwrap();
let mut n_str1 = StringRadix::from_radix("123", 4).unwrap();
let n_str2 = StringRadix::from_radix("444", 5).unwrap();
n1 *= n2;
n_str1 *= n_str2;
n1 = n1.to_radix(8).unwrap();
n_str1 = n_str1.to_radix(8).unwrap();
assert_eq!(n1.radix(), (6424, 8));
assert_eq!(n_str1.radix(), ("6424", 8));
Source§impl PartialEq for StringRadix
impl PartialEq for StringRadix
Source§impl PartialOrd for StringRadix
impl PartialOrd for StringRadix
Source§impl Rem<usize> for StringRadix
impl Rem<usize> for StringRadix
Source§fn rem(self, other: usize) -> Self::Output
fn rem(self, other: usize) -> Self::Output
Performs a %
operation (usize
as rhs).
§Examples
use ognlib::num::radix::{Radix, StringRadix};
let n = Radix::from_radix(444, 5).unwrap();
let n_str = StringRadix::from_radix("444", 5).unwrap();
let res = (n % 27).to_radix(8).unwrap();
let res_str = (n_str % 27).to_radix(8).unwrap();
assert_eq!(res.radix(), (20, 8));
assert_eq!(res_str.radix(), ("20", 8));
Source§type Output = StringRadix
type Output = StringRadix
%
operator.Source§impl Rem for StringRadix
impl Rem for StringRadix
Source§fn rem(self, other: Self) -> Self::Output
fn rem(self, other: Self) -> Self::Output
Performs a %
operation.
§Examples
use ognlib::num::radix::{Radix, StringRadix};
let n1 = Radix::from_radix(123, 4).unwrap();
let n2 = Radix::from_radix(444, 5).unwrap();
let n_str1 = StringRadix::from_radix("123", 4).unwrap();
let n_str2 = StringRadix::from_radix("444", 5).unwrap();
let res = (n2 % n1).to_radix(8).unwrap();
let res_str = (n_str2 % n_str1).to_radix(8).unwrap();
assert_eq!(res.radix(), (20, 8));
assert_eq!(res_str.radix(), ("20", 8));
Source§type Output = StringRadix
type Output = StringRadix
%
operator.Source§impl RemAssign<usize> for StringRadix
impl RemAssign<usize> for StringRadix
Source§fn rem_assign(&mut self, other: usize)
fn rem_assign(&mut self, other: usize)
Performs a %=
operation (usize
as rhs).
§Examples
use ognlib::num::radix::{Radix, StringRadix};
let mut n = Radix::from_radix(444, 5).unwrap();
let mut n_str = StringRadix::from_radix("444", 5).unwrap();
n %= 27;
n_str %= 27;
n = n.to_radix(8).unwrap();
n_str = n_str.to_radix(8).unwrap();
assert_eq!(n.radix(), (20, 8));
assert_eq!(n_str.radix(), ("20", 8));
Source§impl RemAssign for StringRadix
impl RemAssign for StringRadix
Source§fn rem_assign(&mut self, other: Self)
fn rem_assign(&mut self, other: Self)
Performs a %=
operation.
§Examples
use ognlib::num::radix::{Radix, StringRadix};
let n1 = Radix::from_radix(123, 4).unwrap();
let mut n2 = Radix::from_radix(444, 5).unwrap();
let n_str1 = StringRadix::from_radix("123", 4).unwrap();
let mut n_str2 = StringRadix::from_radix("444", 5).unwrap();
n2 %= n1;
n_str2 %= n_str1;
n2 = n2.to_radix(8).unwrap();
n_str2 = n_str2.to_radix(8).unwrap();
assert_eq!(n2.radix(), (20, 8));
assert_eq!(n_str2.radix(), ("20", 8));
Source§impl Sub<usize> for StringRadix
impl Sub<usize> for StringRadix
Source§fn sub(self, other: usize) -> Self::Output
fn sub(self, other: usize) -> Self::Output
Performs a -
operation (usize
is rhs). Result of operation is an absolute
value. Base of resulting number is the base of greater number.
§Examples
use ognlib::num::radix::{Radix, StringRadix};
let n = Radix::from_radix(123, 4).unwrap();
let n_str = StringRadix::from_radix("123", 4).unwrap();
let res = (n - 124).to_radix(8).unwrap();
let res_str = (n_str - 124).to_radix(8).unwrap();
assert_eq!(res.radix(), (141, 8));
assert_eq!(res_str.radix(), ("141", 8));
Source§type Output = StringRadix
type Output = StringRadix
-
operator.Source§impl Sub for StringRadix
impl Sub for StringRadix
Source§fn sub(self, other: Self) -> Self::Output
fn sub(self, other: Self) -> Self::Output
Performs a -
operation. Result of the operation is an absolute value. Base of the
resulting number is the base of the greater number.
§Examples
use ognlib::num::radix::{Radix, StringRadix};
let n1 = Radix::from_radix(123, 4).unwrap();
let n2 = Radix::from_radix(444, 5).unwrap();
let n_str1 = StringRadix::from_radix("123", 4).unwrap();
let n_str2 = StringRadix::from_radix("444", 5).unwrap();
let res = (n1 - n2).to_radix(8).unwrap();
let res_str = (n_str1 - n_str2).to_radix(8).unwrap();
assert_eq!(res.radix(), (141, 8));
assert_eq!(res_str.radix(), ("141", 8));
Source§type Output = StringRadix
type Output = StringRadix
-
operator.Source§impl SubAssign<usize> for StringRadix
impl SubAssign<usize> for StringRadix
Source§fn sub_assign(&mut self, other: usize)
fn sub_assign(&mut self, other: usize)
Performs a -=
operation (usize
as rhs).
The same rules as for common sub are applied.
§Examples
use ognlib::num::radix::{Radix, StringRadix};
let mut n = Radix::from_radix(123, 4).unwrap();
let mut n_str = StringRadix::from_radix("123", 4).unwrap();
n -= 124;
n_str -= 124;
n = n.to_radix(8).unwrap();
n_str = n_str.to_radix(8).unwrap();
assert_eq!(n.radix(), (141, 8));
assert_eq!(n_str.radix(), ("141", 8));
Source§impl SubAssign for StringRadix
impl SubAssign for StringRadix
Source§fn sub_assign(&mut self, other: Self)
fn sub_assign(&mut self, other: Self)
Performs a -=
operation. The same rules as for common sub are applied.
§Examples
use ognlib::num::radix::{Radix, StringRadix};
let mut n1 = Radix::from_radix(123, 4).unwrap();
let n2 = Radix::from_radix(444, 5).unwrap();
let mut n_str1 = StringRadix::from_radix("123", 4).unwrap();
let n_str2 = StringRadix::from_radix("444", 5).unwrap();
n1 -= n2;
n_str1 -= n_str2;
n1 = n1.to_radix(8).unwrap();
n_str1 = n_str1.to_radix(8).unwrap();
assert_eq!(n1.radix(), (141, 8));
assert_eq!(n_str1.radix(), ("141", 8));
impl Eq for StringRadix
impl StructuralPartialEq for StringRadix
Auto Trait Implementations§
impl Freeze for StringRadix
impl RefUnwindSafe for StringRadix
impl Send for StringRadix
impl Sync for StringRadix
impl Unpin for StringRadix
impl UnwindSafe for StringRadix
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more