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>
impl<'a> HexView<'a>
Sourcepub fn print(&self) -> Result<()>
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}Sourcepub fn new(data: &[u8]) -> HexView<'_>
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.
pub fn fmt<W: WriteColor>(&self, buffer: &mut W) -> Result<()>
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more