[][src]Struct dangerous::display::InputDisplay

pub struct InputDisplay<'i> { /* fields omitted */ }

Provides configurable Input formatting.

  • Defaults to formatting an Input to a max displayable width of 1024.
  • The minimum settable display width is 16.

Format string options

Option"heya ♥"&[0xFF, 0xFF, 0xFF, 0xFF, 0xFF b'a']
"{}"[68 65 79 61 20 e2 99 a5][ff ff ff ff ff 61]
"{:#}""heya ♥"[ff ff ff ff ff 'a']
"{:.16}"[68 65 .. 99 a5][ff ff .. ff 61]
"{:#.16}""heya ♥"[ff ff .. 'a']

Example

let formatted = dangerous::input("heya ♥".as_bytes())
    .display()
    .head_tail(16)
    .to_string();
assert_eq!(formatted, "[68 65 .. 99 a5]");

Implementations

impl<'i> InputDisplay<'i>[src]

pub const fn new(input: &'i Input) -> Self[src]

Create a new InputDisplay given Input.

pub fn from_formatter(input: &'i Input, f: &Formatter<'_>) -> Self[src]

Derive an InputDisplay from a fmt::Formatter with defaults.

  • Precision (eg. {:.16}) formatting sets the element limit.
  • Alternate/pretty (eg. {:#}) formatting enables the UTF-8 hint.

pub fn underline(self, value: bool) -> Self[src]

Print the input underline for any provided span.

pub fn str_hint(self, value: bool) -> Self[src]

Hint to the formatter that the Input is a UTF-8 str.

pub fn format(self, format: PreferredFormat) -> Self[src]

Set the preferred way to format the Input.

pub fn head_tail(self, width: usize) -> Self[src]

Show a width of Input at the head of the input and at the tail.

Example

let input = dangerous::input(&[0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF]);
let formatted = input.display().head_tail(16).to_string();

assert_eq!(formatted, "[aa bb .. ee ff]");

pub fn head(self, width: usize) -> Self[src]

Show a width of Input at the head of the input.

Example

let input = dangerous::input(&[0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF]);
let formatted = input.display().head(16).to_string();

assert_eq!(formatted, "[aa bb cc dd ..]");

pub fn tail(self, width: usize) -> Self[src]

Show a width of Input at the tail of the input.

Example

let input = dangerous::input(&[0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF]);
let formatted = input.display().tail(16).to_string();

assert_eq!(formatted, "[.. cc dd ee ff]");

pub fn span(self, span: &'i Input, width: usize) -> Self[src]

Show a width of input Input targeting a span.

Example

let full = &[0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF];
let input = dangerous::input(full);
let span = dangerous::input(&full[5..]);
let formatted = input.display().span(span, 16).to_string();

assert_eq!(formatted, "[.. cc dd ee ff]");

pub fn full(self) -> Self[src]

Shows the all of the elements in the Input.

Example

let input = dangerous::input(&[0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF]);
let formatted = input.display().full().to_string();

assert_eq!(formatted, "[aa bb cc dd ee ff]");

pub fn prepare(&mut self)[src]

Compute the sections of input to display.

pub fn write<W>(&self, w: W) -> Result where
    W: Write
[src]

Writes the Input to a writer with the chosen format.

Errors

Returns core::fmt::Error if failed to write.

Trait Implementations

impl<'i> Clone for InputDisplay<'i>[src]

impl<'i> Debug for InputDisplay<'i>[src]

impl<'i> Display for InputDisplay<'i>[src]

Auto Trait Implementations

impl<'i> RefUnwindSafe for InputDisplay<'i>

impl<'i> Send for InputDisplay<'i>

impl<'i> Sync for InputDisplay<'i>

impl<'i> Unpin for InputDisplay<'i>

impl<'i> UnwindSafe for InputDisplay<'i>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.