pub trait NumberBase: Add + Sub + Div + Mul + Display + Sized + Clone {
    type DecimalType;

    // Required methods
    fn base(&self) -> u16;
    fn greater_than(&self, number: Self) -> bool;
    fn digits(&self) -> &Vec<u16>;
    fn from_string(base: u16, number: &str) -> Self;
    fn from_vec(base: u16, number: Vec<u16>) -> Self;
    fn convert(&mut self, base: u16) -> Self;
    fn display(&self) -> String;
    fn as_binary(&self) -> Self::DecimalType;
    fn as_octal(&self) -> Self::DecimalType;
    fn as_decimal(&self) -> Self::DecimalType;
    fn as_hex(&self) -> String;
}

Required Associated Types§

source

type DecimalType

The type being returned when a decimal is to be returned For instance, the as_octal() function returns either an integer or float depending on whether the struct implementing NumberBase only accepts integers

Required Methods§

source

fn base(&self) -> u16

returns the base of the number

source

fn greater_than(&self, number: Self) -> bool

returns true if the number is greater than the input for this funciton

source

fn digits(&self) -> &Vec<u16>

returns the vector containg the digits in base 10

source

fn from_string(base: u16, number: &str) -> Self

creates an instance of Self from a string

source

fn from_vec(base: u16, number: Vec<u16>) -> Self

creates and instance of Self from a vector

source

fn convert(&mut self, base: u16) -> Self

converts the number to the inputted number base

source

fn display(&self) -> String

returns the value of the number as a string

source

fn as_binary(&self) -> Self::DecimalType

returns an instance of self but in binary

source

fn as_octal(&self) -> Self::DecimalType

returns an instance of self but in octal

source

fn as_decimal(&self) -> Self::DecimalType

returns an instance of self but in decimal

source

fn as_hex(&self) -> String

returns an instance of self but in hex

Implementors§