HexViewBuilder

Struct HexViewBuilder 

Source
pub struct HexViewBuilder<'a> { /* private fields */ }
Expand description

A builder for the HexView struct.

Implementations§

Source§

impl<'a> HexViewBuilder<'a>

Source

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

Constructs a new HexViewBuilder for the given data.

Examples found in repository?
examples/example.rs (line 8)
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 address_offset(self, offset: usize) -> HexViewBuilder<'a>

Configures the address offset of the HexView under construction.

Examples found in repository?
examples/example.rs (line 18)
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 force_color(self) -> Self

Forces any color data to be printed in print, even if redirected to a file or pipe.

Examples found in repository?
examples/example.rs (line 36)
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 codepage<'b: 'a>(self, codepage: &'b [char]) -> HexViewBuilder<'a>

Configures the codepage of the HexView under construction.

Examples found in repository?
examples/example.rs (line 13)
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 replacement_character(self, ch: char) -> HexViewBuilder<'a>

Configures the replacement character of the HexView under construction.

The replacement character is the character that will be used for nonprintable characters in the codepage.

Examples found in repository?
examples/example.rs (line 31)
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 row_width(self, width: usize) -> HexViewBuilder<'a>

Configures the row width of the HexView under construction.

Examples found in repository?
examples/example.rs (line 23)
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 add_colors(self, colors: Colors) -> HexViewBuilder<'a>

Adds the vector of colors to the range color printer

Examples found in repository?
examples/example.rs (lines 37-42)
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 add_color(self, color: &str, range: Range<usize>) -> HexViewBuilder<'a>

Adds the color to the given range, using a more ergonomic API

Source

pub fn finish(self) -> HexView<'a>

Constructs the HexView.

Examples found in repository?
examples/example.rs (line 9)
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}

Auto Trait Implementations§

§

impl<'a> Freeze for HexViewBuilder<'a>

§

impl<'a> RefUnwindSafe for HexViewBuilder<'a>

§

impl<'a> Send for HexViewBuilder<'a>

§

impl<'a> Sync for HexViewBuilder<'a>

§

impl<'a> Unpin for HexViewBuilder<'a>

§

impl<'a> UnwindSafe for HexViewBuilder<'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, 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.