FallibleHexd

Struct FallibleHexd 

Source
pub struct FallibleHexd<R: ReadBytes> { /* private fields */ }
Expand description

A fallible variant of Hexd that surfaces errors from the underlying reader.

Implementations§

Source§

impl<R: ReadBytes> FallibleHexd<R>

Source

pub fn new(reader: R) -> Self

Construct a new Hexd instance with the given reader and default options.

Source

pub fn new_with_options(reader: R, options: HexdOptions) -> Self

Construct a new Hexd instance with the given reader and options.

Source

pub fn dump(self) -> Result<(), R::Error>

Print a hexdump to stdout.

use hxd::IntoFallibleHexd;
use std::fs::OpenOptions;

let f = OpenOptions::new().read(true).open("file.txt").unwrap();

f.hexd().dump().expect("could not read file"); // print a hexdump
Source

pub fn dump_err(self) -> Result<(), R::Error>

Print a hexdump to stderr.

use hxd::IntoFallibleHexd;
use std::fs::OpenOptions;

let f = OpenOptions::new().read(true).open("file.txt").unwrap();

f.hexd().dump_err().expect("could not read file"); // print a hexdump to stderr
Source

pub fn dump_to<W: WriteHexdump + Default>(self) -> Result<W::Output, R::Error>

Construct a default instance of W and write a hexdump to it, returning its output.

use hxd::IntoFallibleHexd;
use std::fs::OpenOptions;

let f = OpenOptions::new().read(true).open("file.txt").unwrap();

let dump = f.hexd().dump_to::<String>().expect("could not read file");
Source

pub fn dump_into<W: WriteHexdump>( self, writer: W, ) -> Result<W::Output, R::Error>

Write a hexdump to an instance of W and return its output.

use hxd::IntoFallibleHexd;
use std::fs::OpenOptions;

let f = OpenOptions::new().read(true).open("file.txt").unwrap();

let v: Vec<String> = Vec::new();
let dump = f.hexd().dump_into(v).expect("could not read file");
Source

pub fn dump_io<W: Write>( self, write: W, ) -> Result<(), ReadWriteError<R::Error, Error>>

Write a hexdump to an object that is Write. The object is wrapped in a BufWriter for improved performance.

use hxd::{IntoFallibleHexd, ReadWriteError};
use std::fs::OpenOptions;

let src = OpenOptions::new().read(true).open("file.txt").unwrap();

let f = OpenOptions::new()
    .write(true)
    .create(true)
    .open("hexdump.txt")
    .unwrap();

src.hexd().dump_io(f).map_err(|err| match err {
    ReadWriteError::Read(e) => panic!("could not read file: {:?}", e),
    ReadWriteError::Write(e) => panic!("could not write to file: {:?}", e),
});
Source

pub fn dump_io_unbuffered<W: Write>( self, write: W, ) -> Result<(), ReadWriteError<R::Error, Error>>

Write a hexdump to an object that is Write. Unlike Self::dump_io, this method does not wrap the object in a BufWriter.

use hxd::{IntoFallibleHexd, ReadWriteError};
use std::fs::OpenOptions;

let src = OpenOptions::new().read(true).open("file.txt").unwrap();

let f = OpenOptions::new()
    .write(true)
    .create(true)
    .open("hexdump.txt")
    .unwrap();

src.hexd().dump_io_unbuffered(f).map_err(|err| match err {
    ReadWriteError::Read(e) => panic!("could not read file: {:?}", e),
    ReadWriteError::Write(e) => panic!("could not write to file: {:?}", e),
});

Trait Implementations§

Source§

impl<R: ReadBytes> HexdOptionsBuilder for FallibleHexd<R>

FallibleHexd implements HexdOptionsBuilder to allow for fluent configuration.

Source§

fn map_options<F: FnOnce(HexdOptions) -> HexdOptions>(self, f: F) -> Self

Return a new instance of Self with the mapping function applied to the instance’s options.
Source§

fn with_options(self, o: HexdOptions) -> Self

Return a new instance of Self with the given options.
Source§

fn base(self, base: Base) -> Self

Set the base system to use. This is equivalent to setting the value of the base field.
Source§

fn hexadecimal(self) -> Self

Set the base system to hexadecimal and the grouping to the default. Read more
Source§

fn decimal(self) -> Self

Set the base system to decimal with spaces rendered for leading zeroes. Set the grouping to 8 equivalently spaced bytes. Read more
Source§

fn octal(self) -> Self

Set the base system to octal with leading zeroes included. Set the grouping to 8 equivalently spaced bytes. Read more
Source§

fn binary(self) -> Self

Set the base system to binary with spaces rendered for leading zeroes. Set the grouping 4 equivalently spaced bytes. Read more
Source§

fn range<R: RangeBounds<usize>>(self, range: R) -> Self

Set a range of bytes to dump. This is equivalent to setting the value of the print_range field.
Source§

fn show_ascii(self, show_ascii: bool) -> Self

Set the value of the show_ascii field.
Source§

fn show_index(self, show_index: bool) -> Self

Set the value of the show_index field.
Source§

fn aligned(self, align: bool) -> Self

Set the value of the align field.
Source§

fn uppercase(self, uppercase: bool) -> Self

Set the value of the uppercase field.
Source§

fn grouping(self, grouping: Grouping) -> Self

Set the value of the grouping field.
Source§

fn ungrouped(self, num_bytes: usize, spacing: Spacing) -> Self

Set the value of the grouping field to Grouping::Ungrouped using the specified parameters.
Source§

fn grouped( self, (group_size, byte_spacing): (GroupSize, Spacing), (num_groups, group_spacing): (usize, Spacing), ) -> Self

Set the value of the grouping field to Grouping::Grouped using the specified parameters.
Source§

fn grouped_by(self, group_size: GroupSize, num_groups: usize) -> Self

Set the value of the grouping field to Grouping::Grouped using the specified parameters and default spacing. This is equivalent to calling grouped with the arguments (GroupSize::Short, Spacing::None) and (num_groups, Spacing::Normal).
Source§

fn autoskip(self, autoskip: bool) -> Self

Set the value of the autoskip field.
Source§

fn offset(self, index_offset: IndexOffset) -> Self

Set the value of the index_offset field.
Source§

fn relative_offset(self, offset: usize) -> Self

Set the value of the index_offset field to IndexOffset::Relative.
Source§

fn absolute_offset(self, offset: usize) -> Self

Set the value of the index_offset field to IndexOffset::Absolute.

Auto Trait Implementations§

§

impl<R> Freeze for FallibleHexd<R>
where R: Freeze,

§

impl<R> RefUnwindSafe for FallibleHexd<R>
where R: RefUnwindSafe,

§

impl<R> Send for FallibleHexd<R>
where R: Send,

§

impl<R> Sync for FallibleHexd<R>
where R: Sync,

§

impl<R> Unpin for FallibleHexd<R>
where R: Unpin,

§

impl<R> UnwindSafe for FallibleHexd<R>
where R: UnwindSafe,

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.