Trait nom::lib::std::fmt::Binary1.0.0[][src]

pub trait Binary {
    fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>;
}
Expand description

b formatting.

The Binary trait should format its output as a number in binary.

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

The alternate flag, #, adds a 0b 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 '101010' in binary

assert_eq!(format!("{:b}", x), "101010");
assert_eq!(format!("{:#b}", x), "0b101010");

assert_eq!(format!("{:b}", -16), "11111111111111111111111111110000");

Implementing Binary on a type:

use std::fmt;

struct Length(i32);

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

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

let l = Length(107);

assert_eq!(format!("l as binary is: {:b}", l), "l as binary is: 1101011");

assert_eq!(
    format!("l as binary is: {:#032b}", l),
    "l as binary is: 0b000000000000000000000001101011"
);

Required methods

Formats the value using the given formatter.

Implementations on Foreign Types

Implementors

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

impl Binary for AtFlags

impl Binary for OFlag

impl Binary for SealFlag

impl Binary for FdFlag

impl Binary for MsFlags

impl Binary for MntFlags

impl Binary for MQ_OFlag

impl Binary for FdFlag

impl Binary for PollFlags

impl Binary for EfdFlags

impl Binary for ProtFlags

impl Binary for MapFlags

impl Binary for MsFlags

impl Binary for Persona

impl Binary for Options

impl Binary for SaFlags

impl Binary for SfdFlags

impl Binary for SockFlag

impl Binary for MsgFlags

impl Binary for SFlag

impl Binary for Mode

impl Binary for FsFlags

impl Binary for InitFlags

impl<'a, Color: Color, T: Binary> Binary for FgColorDisplay<'a, Color, T>

impl<'a, Color: Color, T: Binary> Binary for BgColorDisplay<'a, Color, T>

impl<'a, Color: DynColor, T: Binary> Binary for FgDynColorDisplay<'a, Color, T>

impl<'a, Color: DynColor, T: Binary> Binary for BgDynColorDisplay<'a, Color, T>

impl<'a, Fg: Color, Bg: Color, T: Binary> Binary for ComboColorDisplay<'a, Fg, Bg, T>

impl<T: Binary> Binary for Styled<T>

impl<'a, T: Binary> Binary for BoldDisplay<'a, T>

impl<'a, T: Binary> Binary for DimDisplay<'a, T>

impl<'a, T: Binary> Binary for ItalicDisplay<'a, T>

impl<'a, T: Binary> Binary for UnderlineDisplay<'a, T>

impl<'a, T: Binary> Binary for BlinkDisplay<'a, T>

impl<'a, T: Binary> Binary for BlinkFastDisplay<'a, T>

impl<'a, T: Binary> Binary for ReversedDisplay<'a, T>

impl<'a, T: Binary> Binary for HiddenDisplay<'a, T>

impl<'a, T: Binary> Binary for StrikeThroughDisplay<'a, T>

impl<'a, In, Out, F> Binary for SupportsColorsDisplay<'a, In, Out, F> where
    In: Binary,
    Out: Binary,
    F: Fn(&'a In) -> Out,