pub struct Printer<O: Write, A: AddressFormatting + Clone, B: ByteFormatting + Clone, C: CharFormatting + Clone> { /* private fields */ }
Expand description
The topmost struct for data output
Implementations§
source§impl<O: Write, A: AddressFormatting + Clone, B: ByteFormatting + Clone, C: CharFormatting + Clone> Printer<O, A, B, C>
impl<O: Write, A: AddressFormatting + Clone, B: ByteFormatting + Clone, C: CharFormatting + Clone> Printer<O, A, B, C>
sourcepub fn new(
out: O,
start_address: usize,
config: Config<A, B, C>
) -> Printer<O, A, B, C> ⓘ
pub fn new( out: O, start_address: usize, config: Config<A, B, C> ) -> Printer<O, A, B, C> ⓘ
Customized constructor.
All constructors of the Printer
moves given output. To give it back use finish(mut self)
function
out
- place to ouput string.
start_address
- start address to print.
config
- formatting configuration.
Printer
does no assumptions on start_address
where to start reading data,
it just recieving data chunks in push(...)
function, then increments the start_address
Examples found in repository?
examples/endian.rs (line 38)
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 48 49
fn print_data_per_byte(data: &[u8], is_little_endian: bool) {
use std::io::stdout;
let config = Config::new(
Some(AddressFormatter::new(AddressStyle::Hex(16), Default::default())),
ByteFormatter::new(
Default::default(),
Groupping::RepeatingGroup(Group::new(GROUP_SIZE, " - "), NUM_OF_GROUPS),
"/",
is_little_endian,
Default::default()
),
Some(CharFormatter::default()),
false,
);
let mut printer = Printer::new(stdout(), 0 as usize, config);
for s in data {
assert!(printer
.write(&[*s])
.is_ok());
}
_ = printer.finish();
println!("");
}
More examples
examples/custom.rs (line 25)
4 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
fn main() {
use std::io::stdout;
let config = Config::new(
Some(AddressFormatter::new(
AddressStyle::Dec(8),
Separators::new("", &'\u{1F929}'.to_string()),
)),
ByteFormatter::new(
Default::default(),
Groupping::RepeatingGroup(Group::new(4, "#"), 4),
"",
false,
Default::default(),
),
Some(CharFormatter::new(
".".to_string(),
Separators::new(&'\u{1F4A5}'.to_string(), &'\u{1F4A8}'.to_string()),
)),
true
);
let mut printer = Printer::new(stdout(), 0, config);
let bytes1 = &[222u8, 173, 190, 239];
let bytes2 = &[0xfeu8, 0xed, 0xfa];
let title = b"Custom printing";
for _ in 0..10 {
_ = printer.push(bytes1);
}
_ = printer.push(title);
for _ in 0..11 {
_ = printer.push(bytes2);
}
printer.finish();
}
sourcepub fn finish(self) -> O
pub fn finish(self) -> O
Finalize manually. Prints last unfinished line with paddings and turns back given output
Examples found in repository?
examples/simple.rs (line 23)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
fn main() {
use std::io::stdout;
let mut printer = Printer::default_fmt_with(stdout(), 0);
let bytes1 = &[222u8, 173, 190, 239];
let bytes2 = &[0xfeu8, 0xed, 0xfa];
let title = b"Simple printing";
for _ in 0..10 {
_ = printer.push(bytes1);
}
_ = printer.push(title);
for _ in 0..11 {
_ = printer.push(bytes2);
}
printer.finish();
}
More examples
examples/stdin.rs (line 29)
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
fn main() {
use std::io::stdout;
let mut buf = [0u8; 64];
let stdin = std::io::stdin();
let mut handle = stdin.lock();
let mut printer = Printer::default_fmt_with(stdout(), 0);
while let Ok(size) = handle.read(&mut buf) {
if size == 0 {
break;
}
assert!(printer.write_all(&mut buf[..size]).is_ok());
}
printer.finish();
}
examples/endian.rs (line 47)
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 48 49
fn print_data_per_byte(data: &[u8], is_little_endian: bool) {
use std::io::stdout;
let config = Config::new(
Some(AddressFormatter::new(AddressStyle::Hex(16), Default::default())),
ByteFormatter::new(
Default::default(),
Groupping::RepeatingGroup(Group::new(GROUP_SIZE, " - "), NUM_OF_GROUPS),
"/",
is_little_endian,
Default::default()
),
Some(CharFormatter::default()),
false,
);
let mut printer = Printer::new(stdout(), 0 as usize, config);
for s in data {
assert!(printer
.write(&[*s])
.is_ok());
}
_ = printer.finish();
println!("");
}
examples/custom.rs (line 41)
4 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
fn main() {
use std::io::stdout;
let config = Config::new(
Some(AddressFormatter::new(
AddressStyle::Dec(8),
Separators::new("", &'\u{1F929}'.to_string()),
)),
ByteFormatter::new(
Default::default(),
Groupping::RepeatingGroup(Group::new(4, "#"), 4),
"",
false,
Default::default(),
),
Some(CharFormatter::new(
".".to_string(),
Separators::new(&'\u{1F4A5}'.to_string(), &'\u{1F4A8}'.to_string()),
)),
true
);
let mut printer = Printer::new(stdout(), 0, config);
let bytes1 = &[222u8, 173, 190, 239];
let bytes2 = &[0xfeu8, 0xed, 0xfa];
let title = b"Custom printing";
for _ in 0..10 {
_ = printer.push(bytes1);
}
_ = printer.push(title);
for _ in 0..11 {
_ = printer.push(bytes2);
}
printer.finish();
}
source§impl<O: Write, A: AddressFormatting + Clone, B: ByteFormatting + Clone, C: CharFormatting + Clone> Printer<O, A, B, C>
impl<O: Write, A: AddressFormatting + Clone, B: ByteFormatting + Clone, C: CharFormatting + Clone> Printer<O, A, B, C>
sourcepub fn push(&mut self, bytes: &[u8]) -> Result<usize>
pub fn push(&mut self, bytes: &[u8]) -> Result<usize>
Accepts bytes chunk. Immediately prints first
and second
columns to out
,
third
will printed after second
column is completely filled, or after finalization.
Examples found in repository?
examples/simple.rs (line 14)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
fn main() {
use std::io::stdout;
let mut printer = Printer::default_fmt_with(stdout(), 0);
let bytes1 = &[222u8, 173, 190, 239];
let bytes2 = &[0xfeu8, 0xed, 0xfa];
let title = b"Simple printing";
for _ in 0..10 {
_ = printer.push(bytes1);
}
_ = printer.push(title);
for _ in 0..11 {
_ = printer.push(bytes2);
}
printer.finish();
}
More examples
examples/custom.rs (line 32)
4 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
fn main() {
use std::io::stdout;
let config = Config::new(
Some(AddressFormatter::new(
AddressStyle::Dec(8),
Separators::new("", &'\u{1F929}'.to_string()),
)),
ByteFormatter::new(
Default::default(),
Groupping::RepeatingGroup(Group::new(4, "#"), 4),
"",
false,
Default::default(),
),
Some(CharFormatter::new(
".".to_string(),
Separators::new(&'\u{1F4A5}'.to_string(), &'\u{1F4A8}'.to_string()),
)),
true
);
let mut printer = Printer::new(stdout(), 0, config);
let bytes1 = &[222u8, 173, 190, 239];
let bytes2 = &[0xfeu8, 0xed, 0xfa];
let title = b"Custom printing";
for _ in 0..10 {
_ = printer.push(bytes1);
}
_ = printer.push(title);
for _ in 0..11 {
_ = printer.push(bytes2);
}
printer.finish();
}
source§impl<O: Write, A: AddressFormatting + Clone + Default, B: ByteFormatting + Clone + Default, C: CharFormatting + Clone + Default> Printer<O, A, B, C>
impl<O: Write, A: AddressFormatting + Clone + Default, B: ByteFormatting + Clone + Default, C: CharFormatting + Clone + Default> Printer<O, A, B, C>
pub fn default_with(out: O, start_address: usize) -> Printer<O, A, B, C> ⓘ
source§impl<O: Write> Printer<O, AddressFormatter, ByteFormatter, CharFormatter>
impl<O: Write> Printer<O, AddressFormatter, ByteFormatter, CharFormatter>
sourcepub fn default_fmt_with(
out: O,
start_address: usize
) -> Printer<O, AddressFormatter, ByteFormatter, CharFormatter> ⓘ
pub fn default_fmt_with( out: O, start_address: usize ) -> Printer<O, AddressFormatter, ByteFormatter, CharFormatter> ⓘ
Examples found in repository?
examples/simple.rs (line 7)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
fn main() {
use std::io::stdout;
let mut printer = Printer::default_fmt_with(stdout(), 0);
let bytes1 = &[222u8, 173, 190, 239];
let bytes2 = &[0xfeu8, 0xed, 0xfa];
let title = b"Simple printing";
for _ in 0..10 {
_ = printer.push(bytes1);
}
_ = printer.push(title);
for _ in 0..11 {
_ = printer.push(bytes2);
}
printer.finish();
}
More examples
examples/stdin.rs (line 20)
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
fn main() {
use std::io::stdout;
let mut buf = [0u8; 64];
let stdin = std::io::stdin();
let mut handle = stdin.lock();
let mut printer = Printer::default_fmt_with(stdout(), 0);
while let Ok(size) = handle.read(&mut buf) {
if size == 0 {
break;
}
assert!(printer.write_all(&mut buf[..size]).is_ok());
}
printer.finish();
}
Trait Implementations§
source§impl<O: Write, A: AddressFormatting + Clone, B: ByteFormatting + Clone, C: CharFormatting + Clone> Drop for Printer<O, A, B, C>
impl<O: Write, A: AddressFormatting + Clone, B: ByteFormatting + Clone, C: CharFormatting + Clone> Drop for Printer<O, A, B, C>
source§impl<O: Write, A: AddressFormatting + Clone, B: ByteFormatting + Clone, C: CharFormatting + Clone> Write for Printer<O, A, B, C>
impl<O: Write, A: AddressFormatting + Clone, B: ByteFormatting + Clone, C: CharFormatting + Clone> Write for Printer<O, A, B, C>
source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Write a buffer into this writer, returning how many bytes were written. Read more
source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
🔬This is a nightly-only experimental API. (
can_vector
)1.0.0 · source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Attempts to write an entire buffer into this writer. Read more
source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
🔬This is a nightly-only experimental API. (
write_all_vectored
)Attempts to write multiple buffers into this writer. Read more
Auto Trait Implementations§
impl<O, A, B, C> RefUnwindSafe for Printer<O, A, B, C>where A: RefUnwindSafe, B: RefUnwindSafe, C: RefUnwindSafe, O: RefUnwindSafe,
impl<O, A, B, C> Send for Printer<O, A, B, C>where A: Send, B: Send, C: Send, O: Send,
impl<O, A, B, C> Sync for Printer<O, A, B, C>where A: Sync, B: Sync, C: Sync, O: Sync,
impl<O, A, B, C> Unpin for Printer<O, A, B, C>where A: Unpin, B: Unpin, C: Unpin, O: Unpin,
impl<O, A, B, C> UnwindSafe for Printer<O, A, B, C>where A: UnwindSafe, B: UnwindSafe, C: UnwindSafe, O: UnwindSafe,
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