Trait NumberBase

Source
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

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§