Struct hexplay::HexView

source ·
pub struct HexView<'a> { /* private fields */ }
Expand description

The HexView struct represents the configuration of how to display the data.

Implementations§

source§

impl<'a> HexView<'a>

source

pub fn print(&self) -> Result<()>

Prints the hextable to stdout. If any colors were given during construction, the specified ranges will be printed in color.

Examples found in repository?
examples/example.rs (line 45)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
fn main() {
    let data: Vec<u8> = (0u16..256u16).map(|v| v as u8).collect();

    let default_view = HexViewBuilder::new(&data)
        .finish();
    println!("Default view of all data:\n{}\n\n", default_view);

    let ascii_view = HexViewBuilder::new(&data)
        .codepage(CODEPAGE_ASCII)
        .finish();
    println!("Ascii codepage view of all data:\n{}\n\n", ascii_view);

    let partial_view = HexViewBuilder::new(&data[10..80])
        .address_offset(10)
        .finish();
    println!("Default view of a subslice:\n{}\n\n", partial_view);

    let narrowed_view = HexViewBuilder::new(&data)
        .row_width(10)
        .finish();
    println!("Narrowed view of all data:\n{}\n\n", narrowed_view);

    let combined_view = HexViewBuilder::new(&data[10..180])
        .address_offset(10)
        .codepage(CODEPAGE_1252)
        .row_width(14)
        .replacement_character(std::char::REPLACEMENT_CHARACTER)
        .finish();
    println!("Custom view: \n{}\n\n", combined_view);

    let color_view = HexViewBuilder::new(&data)
        .force_color()
        .add_colors(vec![
            (hexplay::color::red(), 42..72),
            (hexplay::color::yellow_bold(), 10..11),
            (hexplay::color::green(), 32..38),
            (hexplay::color::blue(), 200..226),
        ])
        .finish();
    println!("Coloured view: \n");
    color_view.print().unwrap();
    println!("\n\n");
}
source

pub fn new(data: &[u8]) -> HexView<'_>

Constructs a new HexView for the given data without offset and using codepage 850, a row width of 16 and . as replacement character.

source

pub fn fmt<W: WriteColor>(&self, buffer: &mut W) -> Result<()>

Trait Implementations§

source§

impl<'a> Display for HexView<'a>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for HexView<'a>

§

impl<'a> Send for HexView<'a>

§

impl<'a> Sync for HexView<'a>

§

impl<'a> Unpin for HexView<'a>

§

impl<'a> UnwindSafe for HexView<'a>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.