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)
22fn print_data_per_byte(data: &[u8], is_little_endian: bool) {
23 use std::io::stdout;
24
25 let config = Config::new(
26 Some(AddressFormatter::new(AddressStyle::Hex(16), Default::default())),
27 ByteFormatter::new(
28 Default::default(),
29 Groupping::RepeatingGroup(Group::new(GROUP_SIZE, " - "), NUM_OF_GROUPS),
30 "/",
31 is_little_endian,
32 Default::default()
33 ),
34 Some(CharFormatter::default()),
35 false,
36 );
37
38 let mut printer = Printer::new(stdout(), 0 as usize, config);
39
40
41 for s in data {
42 assert!(printer
43 .write(&[*s])
44 .is_ok());
45 }
46
47 _ = printer.finish();
48 println!("");
49}
More examples
examples/custom.rs (line 25)
4fn main() {
5 use std::io::stdout;
6
7 let config = Config::new(
8 Some(AddressFormatter::new(
9 AddressStyle::Dec(8),
10 Separators::new("", &'\u{1F929}'.to_string()),
11 )),
12 ByteFormatter::new(
13 Default::default(),
14 Groupping::RepeatingGroup(Group::new(4, "#"), 4),
15 "",
16 false,
17 Default::default(),
18 ),
19 Some(CharFormatter::new(
20 ".".to_string(),
21 Separators::new(&'\u{1F4A5}'.to_string(), &'\u{1F4A8}'.to_string()),
22 )),
23 true
24 );
25 let mut printer = Printer::new(stdout(), 0, config);
26
27 let bytes1 = &[222u8, 173, 190, 239];
28 let bytes2 = &[0xfeu8, 0xed, 0xfa];
29 let title = b"Custom printing";
30
31 for _ in 0..10 {
32 _ = printer.push(bytes1);
33 }
34
35 _ = printer.push(title);
36
37 for _ in 0..11 {
38 _ = printer.push(bytes2);
39 }
40
41 printer.finish();
42}
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)
4fn main() {
5 use std::io::stdout;
6
7 let mut printer = Printer::default_fmt_with(stdout(), 0);
8
9 let bytes1 = &[222u8, 173, 190, 239];
10 let bytes2 = &[0xfeu8, 0xed, 0xfa];
11 let title = b"Simple printing";
12
13 for _ in 0..10 {
14 _ = printer.push(bytes1);
15 }
16
17 _ = printer.push(title);
18
19 for _ in 0..11 {
20 _ = printer.push(bytes2);
21 }
22
23 printer.finish();
24}
More examples
examples/stdin.rs (line 29)
13fn main() {
14 use std::io::stdout;
15
16 let mut buf = [0u8; 64];
17 let stdin = std::io::stdin();
18 let mut handle = stdin.lock();
19
20 let mut printer = Printer::default_fmt_with(stdout(), 0);
21
22 while let Ok(size) = handle.read(&mut buf) {
23 if size == 0 {
24 break;
25 }
26 assert!(printer.write_all(&mut buf[..size]).is_ok());
27 }
28
29 printer.finish();
30}
examples/endian.rs (line 47)
22fn print_data_per_byte(data: &[u8], is_little_endian: bool) {
23 use std::io::stdout;
24
25 let config = Config::new(
26 Some(AddressFormatter::new(AddressStyle::Hex(16), Default::default())),
27 ByteFormatter::new(
28 Default::default(),
29 Groupping::RepeatingGroup(Group::new(GROUP_SIZE, " - "), NUM_OF_GROUPS),
30 "/",
31 is_little_endian,
32 Default::default()
33 ),
34 Some(CharFormatter::default()),
35 false,
36 );
37
38 let mut printer = Printer::new(stdout(), 0 as usize, config);
39
40
41 for s in data {
42 assert!(printer
43 .write(&[*s])
44 .is_ok());
45 }
46
47 _ = printer.finish();
48 println!("");
49}
examples/custom.rs (line 41)
4fn main() {
5 use std::io::stdout;
6
7 let config = Config::new(
8 Some(AddressFormatter::new(
9 AddressStyle::Dec(8),
10 Separators::new("", &'\u{1F929}'.to_string()),
11 )),
12 ByteFormatter::new(
13 Default::default(),
14 Groupping::RepeatingGroup(Group::new(4, "#"), 4),
15 "",
16 false,
17 Default::default(),
18 ),
19 Some(CharFormatter::new(
20 ".".to_string(),
21 Separators::new(&'\u{1F4A5}'.to_string(), &'\u{1F4A8}'.to_string()),
22 )),
23 true
24 );
25 let mut printer = Printer::new(stdout(), 0, config);
26
27 let bytes1 = &[222u8, 173, 190, 239];
28 let bytes2 = &[0xfeu8, 0xed, 0xfa];
29 let title = b"Custom printing";
30
31 for _ in 0..10 {
32 _ = printer.push(bytes1);
33 }
34
35 _ = printer.push(title);
36
37 for _ in 0..11 {
38 _ = printer.push(bytes2);
39 }
40
41 printer.finish();
42}
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)
4fn main() {
5 use std::io::stdout;
6
7 let mut printer = Printer::default_fmt_with(stdout(), 0);
8
9 let bytes1 = &[222u8, 173, 190, 239];
10 let bytes2 = &[0xfeu8, 0xed, 0xfa];
11 let title = b"Simple printing";
12
13 for _ in 0..10 {
14 _ = printer.push(bytes1);
15 }
16
17 _ = printer.push(title);
18
19 for _ in 0..11 {
20 _ = printer.push(bytes2);
21 }
22
23 printer.finish();
24}
More examples
examples/custom.rs (line 32)
4fn main() {
5 use std::io::stdout;
6
7 let config = Config::new(
8 Some(AddressFormatter::new(
9 AddressStyle::Dec(8),
10 Separators::new("", &'\u{1F929}'.to_string()),
11 )),
12 ByteFormatter::new(
13 Default::default(),
14 Groupping::RepeatingGroup(Group::new(4, "#"), 4),
15 "",
16 false,
17 Default::default(),
18 ),
19 Some(CharFormatter::new(
20 ".".to_string(),
21 Separators::new(&'\u{1F4A5}'.to_string(), &'\u{1F4A8}'.to_string()),
22 )),
23 true
24 );
25 let mut printer = Printer::new(stdout(), 0, config);
26
27 let bytes1 = &[222u8, 173, 190, 239];
28 let bytes2 = &[0xfeu8, 0xed, 0xfa];
29 let title = b"Custom printing";
30
31 for _ in 0..10 {
32 _ = printer.push(bytes1);
33 }
34
35 _ = printer.push(title);
36
37 for _ in 0..11 {
38 _ = printer.push(bytes2);
39 }
40
41 printer.finish();
42}
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)
4fn main() {
5 use std::io::stdout;
6
7 let mut printer = Printer::default_fmt_with(stdout(), 0);
8
9 let bytes1 = &[222u8, 173, 190, 239];
10 let bytes2 = &[0xfeu8, 0xed, 0xfa];
11 let title = b"Simple printing";
12
13 for _ in 0..10 {
14 _ = printer.push(bytes1);
15 }
16
17 _ = printer.push(title);
18
19 for _ in 0..11 {
20 _ = printer.push(bytes2);
21 }
22
23 printer.finish();
24}
More examples
examples/stdin.rs (line 20)
13fn main() {
14 use std::io::stdout;
15
16 let mut buf = [0u8; 64];
17 let stdin = std::io::stdin();
18 let mut handle = stdin.lock();
19
20 let mut printer = Printer::default_fmt_with(stdout(), 0);
21
22 while let Ok(size) = handle.read(&mut buf) {
23 if size == 0 {
24 break;
25 }
26 assert!(printer.write_all(&mut buf[..size]).is_ok());
27 }
28
29 printer.finish();
30}
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>
Writes 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> Freeze for Printer<O, A, B, C>
impl<O, A, B, C> RefUnwindSafe for Printer<O, A, B, C>
impl<O, A, B, C> Send for Printer<O, A, B, C>
impl<O, A, B, C> Sync for Printer<O, A, B, C>
impl<O, A, B, C> Unpin for Printer<O, A, B, C>
impl<O, A, B, C> UnwindSafe for Printer<O, A, B, C>
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