Trait sp_std::fmt::Octal

1.0.0 · source · []
pub trait Octal {
    fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>;
}
Expand description

o formatting.

The Octal trait should format its output as a number in base-8.

For primitive signed integers (i8 to i128, and isize), negative values are formatted as the two’s complement representation.

The alternate flag, #, adds a 0o in front of the output.

For more information on formatters, see the module-level documentation.

Examples

Basic usage with i32:

let x = 42; // 42 is '52' in octal

assert_eq!(format!("{:o}", x), "52");
assert_eq!(format!("{:#o}", x), "0o52");

assert_eq!(format!("{:o}", -16), "37777777760");

Implementing Octal on a type:

use std::fmt;

struct Length(i32);

impl fmt::Octal for Length {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let val = self.0;

        fmt::Octal::fmt(&val, f) // delegate to i32's implementation
    }
}

let l = Length(9);

assert_eq!(format!("l as octal is: {:o}", l), "l as octal is: 11");

assert_eq!(format!("l as octal is: {:#06o}", l), "l as octal is: 0o0011");

Required methods

Formats the value using the given formatter.

Implementations on Foreign Types

Implementors

impl<O, V> Octal for BitArray<O, V> where
    O: BitOrder,
    V: BitView

impl<T> Octal for Domain<'_, T> where
    T: BitStore

impl<O, T> Octal for BitSlice<O, T> where
    O: BitOrder,
    T: BitStore

impl<O, T> Octal for BitBox<O, T> where
    O: BitOrder,
    T: BitStore

impl<O, T> Octal for BitVec<O, T> where
    O: BitOrder,
    T: BitStore

impl<'a, T: Octal> Octal for StyledValue<'a, T>

impl<'a, I> Octal for Format<'a, I> where
    I: Iterator,
    I::Item: Octal

impl<T, R: Dim, C: Dim, S> Octal for Matrix<T, R, C, S> where
    T: Scalar + Octal,
    S: Storage<T, R, C>,
    DefaultAllocator: Allocator<usize, R, C>, 

impl Octal for BigInt

impl Octal for BigUint

impl<T> Octal for Complex<T> where
    T: Octal + Num + PartialOrd + Clone

impl<T: Octal + Clone + Integer> Octal for Ratio<T>

impl Octal for Protection

impl<A: Array> Octal for ArrayVec<A> where
    A::Item: Octal

impl<'s, T> Octal for SliceVec<'s, T> where
    T: Octal

impl<A: Array> Octal for TinyVec<A> where
    A::Item: Octal

impl<T: Binary + Octal> Octal for FmtBinary<T>

impl<T: Display + Octal> Octal for FmtDisplay<T>

impl<T: LowerExp + Octal> Octal for FmtLowerExp<T>

impl<T: LowerHex + Octal> Octal for FmtLowerHex<T>

impl<T: Octal> Octal for FmtOctal<T>

impl<T: Pointer + Octal> Octal for FmtPointer<T>

impl<T: UpperExp + Octal> Octal for FmtUpperExp<T>

impl<T: UpperHex + Octal> Octal for FmtUpperHex<T>