HexView

Struct 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)
5fn main() {
6    let data: Vec<u8> = (0u16..256u16).map(|v| v as u8).collect();
7
8    let default_view = HexViewBuilder::new(&data)
9        .finish();
10    println!("Default view of all data:\n{}\n\n", default_view);
11
12    let ascii_view = HexViewBuilder::new(&data)
13        .codepage(CODEPAGE_ASCII)
14        .finish();
15    println!("Ascii codepage view of all data:\n{}\n\n", ascii_view);
16
17    let partial_view = HexViewBuilder::new(&data[10..80])
18        .address_offset(10)
19        .finish();
20    println!("Default view of a subslice:\n{}\n\n", partial_view);
21
22    let narrowed_view = HexViewBuilder::new(&data)
23        .row_width(10)
24        .finish();
25    println!("Narrowed view of all data:\n{}\n\n", narrowed_view);
26
27    let combined_view = HexViewBuilder::new(&data[10..180])
28        .address_offset(10)
29        .codepage(CODEPAGE_1252)
30        .row_width(14)
31        .replacement_character(std::char::REPLACEMENT_CHARACTER)
32        .finish();
33    println!("Custom view: \n{}\n\n", combined_view);
34
35    let color_view = HexViewBuilder::new(&data)
36        .force_color()
37        .add_colors(vec![
38            (hexplay::color::red(), 42..72),
39            (hexplay::color::yellow_bold(), 10..11),
40            (hexplay::color::green(), 32..38),
41            (hexplay::color::blue(), 200..226),
42        ])
43        .finish();
44    println!("Coloured view: \n");
45    color_view.print().unwrap();
46    println!("\n\n");
47}
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> Freeze for HexView<'a>

§

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 T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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 T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

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

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.