Struct Radix

Source
pub struct Radix { /* private fields */ }
Expand description

Radix number, that is usually written as numberbase (4448 for example). Base can be only in range 2..=10.

Implementations§

Source§

impl Radix

Source

pub const fn new(base: u8) -> Result<Self, RadixError>

Creates a new Radix.

§Errors

Returns a BaseError when base isn’t correct.

§Examples
use ognlib::num::radix::Radix;

let n = Radix::new(2).unwrap();
assert_eq!(n.number(), 0);
assert_eq!(n.base(), 2);

let e1 = Radix::new(1).unwrap_err();
assert_eq!(e1.to_string(), "Expected base in range `2..=10`, found 1");

let e2 = Radix::new(33).unwrap_err();
assert_eq!(e2.to_string(), "Expected base in range `2..=10`, found 33");
Source

pub fn from_radix(number: usize, base: u8) -> Result<Self, RadixError>

Creates a new Radix with given number and base.

§Panics

Panics if a char from RADIX is somehow not parsed

§Errors

Returns a BaseError if base isn’t correct; NumberError if number isn’t correct.

§Examples
use ognlib::num::radix::Radix;

let n = Radix::from_radix(11010000, 2).unwrap();
assert_eq!(n.number(), 11010000);
assert_eq!(n.base(), 2);

let e = Radix::from_radix(444, 3).unwrap_err();
assert_eq!(e.to_string(), "Number contains a digit (4) that is more or equal than base (3)",);
Source

pub const fn number(&self) -> usize

Returns a number of Radix.

§Example
use ognlib::num::radix::Radix;

let radix = Radix::from_radix(444, 5).unwrap();

assert_eq!(radix.number(), 444);
Source

pub const fn base(&self) -> u8

Returns a base of Radix.

§Example
use ognlib::num::radix::Radix;

let radix = Radix::from_radix(444, 5).unwrap();

assert_eq!(radix.base(), 5);
Source

pub const fn radix(&self) -> (usize, u8)

Returns a full Radix as tuple (number, base).

§Example
use ognlib::num::radix::Radix;

let radix = Radix::from_radix(444, 5).unwrap();

assert_eq!(radix.radix(), (444, 5));
Source

pub fn to_radix(self, base: u8) -> Result<Self, RadixError>

Translate Radix 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;

let n1 = Radix::from(123);
let new1 = n1.to_radix(8).unwrap();

let n2 = Radix::from_radix(173, 8).unwrap();
let new2 = n2.to_radix(10).unwrap();

assert_eq!(new1.radix(), (173, 8));
assert_eq!(new2.radix(), (123, 10));

let e = new2.to_radix(1).unwrap_err();
assert_eq!(e.to_string(), "Expected base in range `2..=10`, found 1");
Source

pub fn to_str_radix(self, base: u8) -> Result<StringRadix, RadixError>

Translate Radix 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::{Radix, StringRadix};

let n = Radix::from_radix(11010000, 2).unwrap();
let res = n.to_str_radix(16).unwrap();
assert_eq!(res.radix(), ("D0", 16));

let e = n.to_str_radix(42).unwrap_err();
assert_eq!(e.to_string(), "Expected base in range `2..=36`, found 42");
Source

pub fn add_to_str( self, other: Self, base: u8, ) -> Result<StringRadix, RadixError>

Sum 2 Radix to new StringRadix.

§Errors

Same as to_str_radix.

§Examples
use ognlib::num::radix::{Radix, StringRadix};

let n1 = Radix::from_radix(123, 4).unwrap();
let n2 = Radix::from_radix(444, 5).unwrap();

let res = Radix::add_to_str(n1, n2, 16).unwrap();
assert_eq!(res.radix(), ("97", 16));
Source

pub fn sub_to_str( self, other: Self, base: u8, ) -> Result<StringRadix, RadixError>

Sub 2 Radix to new StringRadix.

§Errors

Same as to_str_radix.

§Examples
use ognlib::num::radix::{Radix, StringRadix};

let n1 = Radix::from_radix(123, 4).unwrap();
let n2 = Radix::from_radix(444, 5).unwrap();

let res = Radix::sub_to_str(n2, n1, 16).unwrap();
assert_eq!(res.radix(), ("61", 16));
Source

pub fn mul_to_str( self, other: Self, base: u8, ) -> Result<StringRadix, RadixError>

Mul 2 Radix to new StringRadix.

§Errors

Same as to_str_radix.

§Examples
use ognlib::num::radix::{Radix, StringRadix};

let n1 = Radix::from_radix(123, 4).unwrap();
let n2 = Radix::from_radix(444, 5).unwrap();

let res = Radix::mul_to_str(n1, n2, 16).unwrap();
assert_eq!(res.radix(), ("D14", 16));

Trait Implementations§

Source§

impl Add<usize> for Radix

Source§

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 = Radix

The resulting type after applying the + operator.
Source§

impl Add for Radix

Source§

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 = Radix

The resulting type after applying the + operator.
Source§

impl AddAssign<usize> for Radix

Source§

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 Radix

Source§

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 Radix

Source§

fn clone(&self) -> Radix

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Radix

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Div<usize> for Radix

Source§

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 = Radix

The resulting type after applying the / operator.
Source§

impl Div for Radix

Source§

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 = Radix

The resulting type after applying the / operator.
Source§

impl DivAssign<usize> for Radix

Source§

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 Radix

Source§

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<&Radix> for i16

Source§

fn from(radix: &Radix) -> Self

Converts a Radix into primitive int.

§Example
use ognlib::num::radix::Radix;

let radix = Radix::from_radix(444, 5).unwrap();
let num: i16 = radix.into();

assert_eq!(num, 124i16);
Source§

impl From<&Radix> for i32

Source§

fn from(radix: &Radix) -> Self

Converts a Radix into primitive int.

§Example
use ognlib::num::radix::Radix;

let radix = Radix::from_radix(444, 5).unwrap();
let num: i32 = radix.into();

assert_eq!(num, 124i32);
Source§

impl From<&Radix> for i64

Source§

fn from(radix: &Radix) -> Self

Converts a Radix into primitive int.

§Example
use ognlib::num::radix::Radix;

let radix = Radix::from_radix(444, 5).unwrap();
let num: i64 = radix.into();

assert_eq!(num, 124i64);
Source§

impl From<&Radix> for i8

Source§

fn from(radix: &Radix) -> Self

Converts a Radix into primitive int.

§Example
use ognlib::num::radix::Radix;

let radix = Radix::from_radix(444, 5).unwrap();
let num: i8 = radix.into();

assert_eq!(num, 124i8);
Source§

impl From<&Radix> for isize

Source§

fn from(radix: &Radix) -> Self

Converts a Radix into primitive int.

§Example
use ognlib::num::radix::Radix;

let radix = Radix::from_radix(444, 5).unwrap();
let num: isize = radix.into();

assert_eq!(num, 124isize);
Source§

impl From<&Radix> for u16

Source§

fn from(radix: &Radix) -> Self

Converts a Radix into primitive int.

§Example
use ognlib::num::radix::Radix;

let radix = Radix::from_radix(444, 5).unwrap();
let num: u16 = radix.into();

assert_eq!(num, 124u16);
Source§

impl From<&Radix> for u32

Source§

fn from(radix: &Radix) -> Self

Converts a Radix into primitive int.

§Example
use ognlib::num::radix::Radix;

let radix = Radix::from_radix(444, 5).unwrap();
let num: u32 = radix.into();

assert_eq!(num, 124u32);
Source§

impl From<&Radix> for u64

Source§

fn from(radix: &Radix) -> Self

Converts a Radix into primitive int.

§Example
use ognlib::num::radix::Radix;

let radix = Radix::from_radix(444, 5).unwrap();
let num: u64 = radix.into();

assert_eq!(num, 124u64);
Source§

impl From<&Radix> for u8

Source§

fn from(radix: &Radix) -> Self

Converts a Radix into primitive int.

§Example
use ognlib::num::radix::Radix;

let radix = Radix::from_radix(444, 5).unwrap();
let num: u8 = radix.into();

assert_eq!(num, 124u8);
Source§

impl From<&Radix> for usize

Source§

fn from(radix: &Radix) -> Self

Converts a Radix into primitive int.

§Example
use ognlib::num::radix::Radix;

let radix = Radix::from_radix(444, 5).unwrap();
let num: usize = radix.into();

assert_eq!(num, 124usize);
Source§

impl From<Radix> for i16

Source§

fn from(radix: Radix) -> Self

Converts a Radix into primitive int.

§Example
use ognlib::num::radix::Radix;

let radix = Radix::from_radix(444, 5).unwrap();
let num: i16 = radix.into();

assert_eq!(num, 124i16);
Source§

impl From<Radix> for i32

Source§

fn from(radix: Radix) -> Self

Converts a Radix into primitive int.

§Example
use ognlib::num::radix::Radix;

let radix = Radix::from_radix(444, 5).unwrap();
let num: i32 = radix.into();

assert_eq!(num, 124i32);
Source§

impl From<Radix> for i64

Source§

fn from(radix: Radix) -> Self

Converts a Radix into primitive int.

§Example
use ognlib::num::radix::Radix;

let radix = Radix::from_radix(444, 5).unwrap();
let num: i64 = radix.into();

assert_eq!(num, 124i64);
Source§

impl From<Radix> for i8

Source§

fn from(radix: Radix) -> Self

Converts a Radix into primitive int.

§Example
use ognlib::num::radix::Radix;

let radix = Radix::from_radix(444, 5).unwrap();
let num: i8 = radix.into();

assert_eq!(num, 124i8);
Source§

impl From<Radix> for isize

Source§

fn from(radix: Radix) -> Self

Converts a Radix into primitive int.

§Example
use ognlib::num::radix::Radix;

let radix = Radix::from_radix(444, 5).unwrap();
let num: isize = radix.into();

assert_eq!(num, 124isize);
Source§

impl From<Radix> for u16

Source§

fn from(radix: Radix) -> Self

Converts a Radix into primitive int.

§Example
use ognlib::num::radix::Radix;

let radix = Radix::from_radix(444, 5).unwrap();
let num: u16 = radix.into();

assert_eq!(num, 124u16);
Source§

impl From<Radix> for u32

Source§

fn from(radix: Radix) -> Self

Converts a Radix into primitive int.

§Example
use ognlib::num::radix::Radix;

let radix = Radix::from_radix(444, 5).unwrap();
let num: u32 = radix.into();

assert_eq!(num, 124u32);
Source§

impl From<Radix> for u64

Source§

fn from(radix: Radix) -> Self

Converts a Radix into primitive int.

§Example
use ognlib::num::radix::Radix;

let radix = Radix::from_radix(444, 5).unwrap();
let num: u64 = radix.into();

assert_eq!(num, 124u64);
Source§

impl From<Radix> for u8

Source§

fn from(radix: Radix) -> Self

Converts a Radix into primitive int.

§Example
use ognlib::num::radix::Radix;

let radix = Radix::from_radix(444, 5).unwrap();
let num: u8 = radix.into();

assert_eq!(num, 124u8);
Source§

impl From<Radix> for usize

Source§

fn from(radix: Radix) -> Self

Converts a Radix into primitive int.

§Example
use ognlib::num::radix::Radix;

let radix = Radix::from_radix(444, 5).unwrap();
let num: usize = radix.into();

assert_eq!(num, 124usize);
Source§

impl From<i16> for Radix

Source§

fn from(number: i16) -> Self

Creates a new Radix with base 10 and given integer number.

§Examples
use ognlib::num::radix::Radix;

let radix = Radix::from(123i16);
assert_eq!(radix.number(), 123usize);
assert_eq!(radix.base(), 10);
Source§

impl From<i32> for Radix

Source§

fn from(number: i32) -> Self

Creates a new Radix with base 10 and given integer number.

§Examples
use ognlib::num::radix::Radix;

let radix = Radix::from(123i32);
assert_eq!(radix.number(), 123usize);
assert_eq!(radix.base(), 10);
Source§

impl From<i64> for Radix

Source§

fn from(number: i64) -> Self

Creates a new Radix with base 10 and given integer number.

§Examples
use ognlib::num::radix::Radix;

let radix = Radix::from(123i64);
assert_eq!(radix.number(), 123usize);
assert_eq!(radix.base(), 10);
Source§

impl From<i8> for Radix

Source§

fn from(number: i8) -> Self

Creates a new Radix with base 10 and given integer number.

§Examples
use ognlib::num::radix::Radix;

let radix = Radix::from(123i8);
assert_eq!(radix.number(), 123usize);
assert_eq!(radix.base(), 10);
Source§

impl From<isize> for Radix

Source§

fn from(number: isize) -> Self

Creates a new Radix with base 10 and given integer number.

§Examples
use ognlib::num::radix::Radix;

let radix = Radix::from(123isize);
assert_eq!(radix.number(), 123usize);
assert_eq!(radix.base(), 10);
Source§

impl From<u16> for Radix

Source§

fn from(number: u16) -> Self

Creates a new Radix with base 10 and given integer number.

§Examples
use ognlib::num::radix::Radix;

let radix = Radix::from(123u16);
assert_eq!(radix.number(), 123usize);
assert_eq!(radix.base(), 10);
Source§

impl From<u32> for Radix

Source§

fn from(number: u32) -> Self

Creates a new Radix with base 10 and given integer number.

§Examples
use ognlib::num::radix::Radix;

let radix = Radix::from(123u32);
assert_eq!(radix.number(), 123usize);
assert_eq!(radix.base(), 10);
Source§

impl From<u64> for Radix

Source§

fn from(number: u64) -> Self

Creates a new Radix with base 10 and given integer number.

§Examples
use ognlib::num::radix::Radix;

let radix = Radix::from(123u64);
assert_eq!(radix.number(), 123usize);
assert_eq!(radix.base(), 10);
Source§

impl From<u8> for Radix

Source§

fn from(number: u8) -> Self

Creates a new Radix with base 10 and given integer number.

§Examples
use ognlib::num::radix::Radix;

let radix = Radix::from(123u8);
assert_eq!(radix.number(), 123usize);
assert_eq!(radix.base(), 10);
Source§

impl From<usize> for Radix

Source§

fn from(number: usize) -> Self

Creates a new Radix with base 10 and given integer number.

§Examples
use ognlib::num::radix::Radix;

let radix = Radix::from(123usize);
assert_eq!(radix.number(), 123usize);
assert_eq!(radix.base(), 10);
Source§

impl FromStr for Radix

Source§

fn from_str(number: &str) -> Result<Self, Self::Err>

Creates a new Radix with base 10 and given str number.

§Errors

Returns ParseIntError if number contains invalid digits.

§Examples
use {core::str::FromStr, ognlib::num::radix::Radix};

let n = Radix::from_str("123").unwrap();
assert_eq!(n.radix(), (123, 10));

let e = Radix::from_str("12A").unwrap_err();
assert_eq!(e.to_string(), "invalid digit found in string");
Source§

type Err = ParseIntError

The associated error which can be returned from parsing.
Source§

impl Mul<usize> for Radix

Source§

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 = Radix

The resulting type after applying the * operator.
Source§

impl Mul for Radix

Source§

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 = Radix

The resulting type after applying the * operator.
Source§

impl MulAssign<usize> for Radix

Source§

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 Radix

Source§

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 Ord for Radix

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
Source§

fn max(self, other: Self) -> Self

Compares and returns the maximum of two values. Read more
Source§

fn min(self, other: Self) -> Self

Compares and returns the minimum of two values. Read more
Source§

fn clamp(self, min: Self, max: Self) -> Self

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Radix

Source§

fn eq(&self, other: &Radix) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Radix

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
Source§

fn gt(&self, other: &Self) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
Source§

fn lt(&self, other: &Self) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
Source§

fn le(&self, other: &Self) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
Source§

fn ge(&self, other: &Self) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Rem<usize> for Radix

Source§

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 = Radix

The resulting type after applying the % operator.
Source§

impl Rem for Radix

Source§

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 = Radix

The resulting type after applying the % operator.
Source§

impl RemAssign<usize> for Radix

Source§

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 Radix

Source§

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 Radix

Source§

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 = Radix

The resulting type after applying the - operator.
Source§

impl Sub for Radix

Source§

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 = Radix

The resulting type after applying the - operator.
Source§

impl SubAssign<usize> for Radix

Source§

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 Radix

Source§

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));
Source§

impl Copy for Radix

Source§

impl Eq for Radix

Source§

impl StructuralPartialEq for Radix

Auto Trait Implementations§

§

impl Freeze for Radix

§

impl RefUnwindSafe for Radix

§

impl Send for Radix

§

impl Sync for Radix

§

impl Unpin for Radix

§

impl UnwindSafe for Radix

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T, Rhs> NumAssignOps<Rhs> for T
where T: AddAssign<Rhs> + SubAssign<Rhs> + MulAssign<Rhs> + DivAssign<Rhs> + RemAssign<Rhs>,

Source§

impl<T, Rhs, Output> NumOps<Rhs, Output> for T
where T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>,