Trait Binary

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

core b formatting.

Re-exported from core::fmt:: .


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!("{x:b}"), "101010");
assert_eq!(format!("{x:#b}"), "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: {l:b}"), "l as binary is: 1101011");

assert_eq!(
    // Note that the `0b` prefix added by `#` is included in the total width, so we
    // need to add two to correctly display all 32 bits.
    format!("l as binary is: {l:#034b}"),
    "l as binary is: 0b00000000000000000000000001101011"
);

Required Methods§

1.0.0 · Source

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter.

§Errors

This function should return Err if, and only if, the provided Formatter returns Err. String formatting is considered an infallible operation; this function only returns a Result because writing to the underlying stream might fail and it must provide a way to propagate the fact that an error has occurred back up the stack.

Implementors§

1.0.0 · Source§

impl Binary for i8

1.0.0 · Source§

impl Binary for i16

1.0.0 · Source§

impl Binary for i32

1.0.0 · Source§

impl Binary for i64

1.0.0 · Source§

impl Binary for i128

1.0.0 · Source§

impl Binary for isize

1.0.0 · Source§

impl Binary for u8

1.0.0 · Source§

impl Binary for u16

1.0.0 · Source§

impl Binary for u32

1.0.0 · Source§

impl Binary for u64

1.0.0 · Source§

impl Binary for u128

1.0.0 · Source§

impl Binary for usize

§

impl Binary for KeyEventState

§

impl Binary for KeyModifiers

§

impl Binary for KeyboardEnhancementFlags

§

impl Binary for FileAccess

§

impl Binary for Root

§

impl Binary for FileChooserType

§

impl Binary for FileDialogOptions

§

impl Binary for LineStyle

§

impl Binary for Align

§

impl Binary for CallbackTrigger

§

impl Binary for Damage

§

impl Binary for devela::_dep::fltk::enums::Mode

§

impl Binary for Shortcut

§

impl Binary for GridAlign

§

impl Binary for AnimGifImageFlags

§

impl Binary for MenuFlag

§

impl Binary for Attrib

§

impl Binary for CharFlags

§

impl Binary for OutFlags

Source§

impl Binary for BigInt

§

impl Binary for devela::_dep::rustix::event::epoll::CreateFlags

§

impl Binary for EventfdFlags

§

impl Binary for PollFlags

§

impl Binary for devela::_dep::rustix::fs::inotify::CreateFlags

§

impl Binary for ReadFlags

§

impl Binary for WatchFlags

§

impl Binary for Access

§

impl Binary for AtFlags

§

impl Binary for FallocateFlags

§

impl Binary for FdFlags

§

impl Binary for IFlags

§

impl Binary for MemfdFlags

§

impl Binary for devela::_dep::rustix::fs::Mode

§

impl Binary for MountFlags

§

impl Binary for MountPropagationFlags

§

impl Binary for OFlags

§

impl Binary for RenameFlags

§

impl Binary for ResolveFlags

§

impl Binary for SealFlags

§

impl Binary for StatVfsMountFlags

§

impl Binary for StatxFlags

§

impl Binary for UnmountFlags

§

impl Binary for XattrFlags

§

impl Binary for DupFlags

§

impl Binary for ReadWriteFlags

§

impl Binary for EventFlags

§

impl Binary for IoringAcceptFlags

§

impl Binary for IoringAsyncCancelFlags

§

impl Binary for IoringCqFlags

§

impl Binary for IoringCqeFlags

§

impl Binary for IoringEnterFlags

§

impl Binary for IoringFeatureFlags

§

impl Binary for IoringFsyncFlags

§

impl Binary for IoringMsgringFlags

§

impl Binary for IoringOpFlags

§

impl Binary for IoringPollFlags

§

impl Binary for IoringRecvFlags

§

impl Binary for IoringRegisterFlags

§

impl Binary for IoringRsrcFlags

§

impl Binary for IoringSendFlags

§

impl Binary for IoringSetupFlags

§

impl Binary for IoringSqFlags

§

impl Binary for IoringSqeFlags

§

impl Binary for IoringTimeoutFlags

§

impl Binary for RecvFlags

§

impl Binary for RecvmsgOutFlags

§

impl Binary for SendFlags

§

impl Binary for SocketFlags

§

impl Binary for devela::_dep::rustix::io_uring::SpliceFlags

§

impl Binary for MapFlags

§

impl Binary for MlockAllFlags

§

impl Binary for MlockFlags

§

impl Binary for MprotectFlags

§

impl Binary for MremapFlags

§

impl Binary for MsyncFlags

§

impl Binary for ProtFlags

§

impl Binary for UserfaultfdFlags

§

impl Binary for FsMountFlags

§

impl Binary for FsOpenFlags

§

impl Binary for FsPickFlags

§

impl Binary for MountAttrFlags

§

impl Binary for MoveMountFlags

§

impl Binary for OpenTreeFlags

§

impl Binary for SockaddrXdpFlags

§

impl Binary for XdpDescOptions

§

impl Binary for XdpOptionsFlags

§

impl Binary for XdpRingFlags

§

impl Binary for XdpUmemRegFlags

§

impl Binary for PipeFlags

§

impl Binary for devela::_dep::rustix::pipe::SpliceFlags

§

impl Binary for FloatingPointEmulationControl

§

impl Binary for FloatingPointExceptionMode

§

impl Binary for MembarrierQuery

§

impl Binary for PidfdFlags

§

impl Binary for PidfdGetfdFlags

§

impl Binary for SpeculationFeatureControl

§

impl Binary for SpeculationFeatureState

§

impl Binary for UnalignedAccessControl

§

impl Binary for WaitOptions

§

impl Binary for WaitidOptions

§

impl Binary for OpenptFlags

§

impl Binary for GetRandomFlags

§

impl Binary for ShmOFlags

§

impl Binary for ControlModes

§

impl Binary for InputModes

§

impl Binary for LocalModes

§

impl Binary for OutputModes

§

impl Binary for CapabilitiesSecureBits

§

impl Binary for CapabilityFlags

§

impl Binary for devela::_dep::rustix::thread::FutexFlags

§

impl Binary for TaggedAddressMode

§

impl Binary for ThreadNameSpaceType

§

impl Binary for UnshareFlags

§

impl Binary for TimerfdFlags

§

impl Binary for TimerfdTimerFlags

§

impl Binary for devela::_dep::sdl2::image::InitFlag

§

impl Binary for devela::_dep::sdl2::keyboard::Mod

§

impl Binary for devela::_dep::sdl2::messagebox::MessageBoxButtonFlag

§

impl Binary for devela::_dep::sdl2::messagebox::MessageBoxFlag

§

impl Binary for devela::_dep::sdl2::mixer::InitFlag

§

impl Binary for FontStyle

§

impl Binary for GlobFlags

§

impl Binary for devela::_dep::sdl3::keyboard::Mod

§

impl Binary for devela::_dep::sdl3::messagebox::MessageBoxButtonFlag

§

impl Binary for devela::_dep::sdl3::messagebox::MessageBoxFlag

§

impl Binary for Channels

§

impl Binary for f32x4

§

impl Binary for f32x8

§

impl Binary for f64x2

§

impl Binary for f64x4

§

impl Binary for i8x16

§

impl Binary for i8x32

§

impl Binary for i16x8

§

impl Binary for i16x16

§

impl Binary for i32x4

§

impl Binary for i32x8

§

impl Binary for i64x2

§

impl Binary for i64x4

§

impl Binary for u8x16

§

impl Binary for u16x8

§

impl Binary for u16x16

§

impl Binary for u32x4

§

impl Binary for u32x8

§

impl Binary for u64x2

§

impl Binary for u64x4

Source§

impl Binary for ExampleBitfield

Available on crate feature _bit_u8 and (doc or test) only.
Source§

impl Binary for ExampleBitfieldCustom

Available on crate feature _bit_u8 and (doc or test) only.
Source§

impl Binary for ExampleBitfieldExtra

Available on crate feature _bit_u8 and (doc or test) only.
Source§

impl Binary for ExampleEnumSet

Available on doc or test only.
Source§

impl Binary for char7

Source§

impl Binary for char8

Source§

impl Binary for char16

Source§

impl Binary for DrumFrame8

Available on crate feature audio only.
§

impl Binary for m128

§

impl Binary for m128d

§

impl Binary for m128i

§

impl Binary for m256

§

impl Binary for m256d

§

impl Binary for m256i

§

impl Binary for EfdFlags

§

impl Binary for EpollCreateFlags

§

impl Binary for EpollFlags

§

impl Binary for EventMask

§

impl Binary for Flags

§

impl Binary for PortCap

§

impl Binary for PortType

§

impl Binary for Remove

§

impl Binary for Transformations

§

impl Binary for WatchMask

§

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

Source§

impl<'t, T, F, U> Binary for OptionFmtOrElse<'t, T, F>
where T: Binary, F: Fn() -> U, U: Display,

Source§

impl<'t, T, U> Binary for OptionFmtOr<'t, T, U>
where T: Binary, U: Display,

1.0.0 · Source§

impl<T> Binary for &T
where T: Binary + ?Sized,

1.0.0 · Source§

impl<T> Binary for &mut T
where T: Binary + ?Sized,

1.28.0 · Source§

impl<T> Binary for NonZero<T>

Source§

impl<T> Binary for OptionFmt<'_, T>
where T: Binary,

1.74.0 · Source§

impl<T> Binary for Saturating<T>
where T: Binary,

1.11.0 · Source§

impl<T> Binary for Wrapping<T>
where T: Binary,

Source§

impl<T: Binary> Binary for Frac<T>

Source§

impl<T: Binary> Binary for Int<T>

Source§

impl<T: Binary> Binary for Bitwise<T>

Source§

impl<const V: i8> Binary for devela::_info::examples::niche::NonValueI8<V>

Available on doc or test only.
Source§

impl<const V: i8> Binary for devela::all::NonValueI8<V>

Source§

impl<const V: u8> Binary for NonValueU8<V>

Source§

impl<const V: u16> Binary for NonValueU16<V>