Trait num_runtime_fmt::numeric_trait::Numeric[][src]

pub trait Numeric {
    type BinIter: Iterator<Item = char>;
    type OctIter: Iterator<Item = char>;
    type DecLeftIter: Iterator<Item = char>;
    type DecRightIter: Iterator<Item = char>;
    type HexIter: Iterator<Item = char>;
    fn binary(&self) -> Option<Self::BinIter>;
fn octal(&self) -> Option<Self::OctIter>;
fn decimal(&self) -> (Self::DecLeftIter, Option<Self::DecRightIter>);
fn hex(&self) -> Option<Self::HexIter>;
fn is_negative(&self) -> bool; }

This trait enables a type to be formatted by NumFmt.

The fundamental abstraction used is an optional iterator over a stream of characters. Returning None always indicates that representation in that base is not available for this type. Any particular function implemented for a type should always return either None or Some; it should not depend on the value being formatted.

In all cases, when implemented, the iterators must iterate away from the decimal: for a representation of N in base B, it must return the appropriate digit for B**0, B**1, … BN**k where k is ceil(log_B(N)).

Iterators should only return digits within the appropriate range for the base. All other formatting is handled by the formatter.

Iterator types must be declared even when the appropriate function always returns None. In those cases, std::iter::Empty is appropriate.

Associated Types

type BinIter: Iterator<Item = char>[src]

Iterate over binary digits of this number.

Legal output characters: [01].

type OctIter: Iterator<Item = char>[src]

Iterate over octal digits of this number.

Legal output characters: [0-7].

type DecLeftIter: Iterator<Item = char>[src]

Iterate over decimal digits of this number which are >= 1.

Legal output characters: [0-9].

type DecRightIter: Iterator<Item = char>[src]

Iterate over decimal digits of this number which are < 1.

Legal output characters: [0-9].

This should iterate away from the decimal: for a representation of N, it must return the appropriate digit for 10**-1, 10**-2, etc.

type HexIter: Iterator<Item = char>[src]

Iterate over hexadecimal digits of this number, with letters as lowercase.

Legal output characters: [0-9a-f].

Loading content...

Required methods

fn binary(&self) -> Option<Self::BinIter>[src]

Iterate over the binary digits of this number, from least to most significant.

This function should always return either None or Some; it should not depend on the value of self.

fn octal(&self) -> Option<Self::OctIter>[src]

Iterate over the octal digits of this number, from least to most significant.

This function should always return either None or Some; it should not depend on the value of self.

fn decimal(&self) -> (Self::DecLeftIter, Option<Self::DecRightIter>)[src]

Produce a pair of iterators over the decimal digits of this number.

DecLeftIter

Self::DecLeftIter must iterate over the decimal digits of this number which are >= 1, from least to most significant. Note that it is assumed that all numeric types can produce a decimal representation of an integer component.

DecRightIter

Self::DecRightIter should iterate away from the decimal: for a representation of N, it must return the appropriate digit for 10**-1, 10**-2, etc.

It is an exception to the general rule; it may return None or Some according to the value of self.

If Self is not an integral type, such as f64, but self is an integer, like 1.0, then the output will vary by what this function returns as follows:

  • None => "1"
  • Some(std::iter::empty()) => "1."
  • Some(std::iter::once('0')) => “1.0”`

fn hex(&self) -> Option<Self::HexIter>[src]

Iterate over the hexadecimal digits of this number, with letters as lowercase.

This function should always return either None or Some; it should not depend on the value of self.

Note that the implementation must provide only the lowercase implementation. The formatter uppercases the output of this function when the user requests uppercase hexadecimal.

fn is_negative(&self) -> bool[src]

true when this value is less than 0.

Loading content...

Implementations on Foreign Types

impl Numeric for u8[src]

type BinIter = BinIter<u8>

type OctIter = OctIter<u8>

type DecLeftIter = DecIter

type DecRightIter = DecIter

type HexIter = HexIter<u8>

impl Numeric for u16[src]

type BinIter = BinIter<u16>

type OctIter = OctIter<u16>

type DecLeftIter = DecIter

type DecRightIter = DecIter

type HexIter = HexIter<u16>

impl Numeric for u32[src]

type BinIter = BinIter<u32>

type OctIter = OctIter<u32>

type DecLeftIter = DecIter

type DecRightIter = DecIter

type HexIter = HexIter<u32>

impl Numeric for u64[src]

type BinIter = BinIter<u64>

type OctIter = OctIter<u64>

type DecLeftIter = DecIter

type DecRightIter = DecIter

type HexIter = HexIter<u64>

impl Numeric for u128[src]

type BinIter = BinIter<u128>

type OctIter = OctIter<u128>

type DecLeftIter = DecIter

type DecRightIter = DecIter

type HexIter = HexIter<u128>

impl Numeric for usize[src]

type BinIter = BinIter<usize>

type OctIter = OctIter<usize>

type DecLeftIter = DecIter

type DecRightIter = DecIter

type HexIter = HexIter<usize>

impl Numeric for i16[src]

type BinIter = BinIter<i16>

type OctIter = OctIter<i16>

type DecLeftIter = DecIter

type DecRightIter = DecIter

type HexIter = HexIter<i16>

impl Numeric for i32[src]

type BinIter = BinIter<i32>

type OctIter = OctIter<i32>

type DecLeftIter = DecIter

type DecRightIter = DecIter

type HexIter = HexIter<i32>

impl Numeric for i64[src]

type BinIter = BinIter<i64>

type OctIter = OctIter<i64>

type DecLeftIter = DecIter

type DecRightIter = DecIter

type HexIter = HexIter<i64>

impl Numeric for i128[src]

type BinIter = BinIter<i128>

type OctIter = OctIter<i128>

type DecLeftIter = DecIter

type DecRightIter = DecIter

type HexIter = HexIter<i128>

impl Numeric for isize[src]

type BinIter = BinIter<isize>

type OctIter = OctIter<isize>

type DecLeftIter = DecIter

type DecRightIter = DecIter

type HexIter = HexIter<isize>

impl Numeric for f32[src]

type BinIter = Empty<char>

type OctIter = Empty<char>

type DecLeftIter = DecIter

type DecRightIter = DecIter

type HexIter = Empty<char>

impl Numeric for f64[src]

type BinIter = Empty<char>

type OctIter = Empty<char>

type DecLeftIter = DecIter

type DecRightIter = DecIter

type HexIter = Empty<char>

Loading content...

Implementors

Loading content...