1
2
3
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
//! # show-bytes
//!
//! Display bytes as printable ascii with escape sequences as needed.
//!
//! ## Examples
//!
//! ```rust
//! use show_bytes::println;
//!
//! // byte slice
//! let bytes_slice: &[u8] = &[72, 101, 108, 108, 111, 0, 255];
//! println(bytes_slice);
//!
//! // byte vector
//! let bytes_vec: Vec<u8> = vec![72, 101, 108, 108, 111, 0, 255];
//! println(&bytes_vec);
//! println(bytes_vec);
//!
//! // byte array
//! let bytes_array: [u8; 7] = [72, 101, 108, 108, 111, 0, 255];
//! println(bytes_array);
//! println(&bytes_array);
//!
//! // byte iterator
//! let mut bytes_iter = [72, 101, 108, 108, 111, 0, 255].iter();
//! println(bytes_iter.clone());
//! println(&mut bytes_iter);
//!
//! // &str
//! let bytes_str: &str = "hello\0\x7f";
//! println(bytes_str.bytes());
//! let bytes_str = &bytes_str;
//! println(bytes_str.bytes());
//!
//! // String
//! let bytes_string: String = bytes_str.to_string();
//! println(bytes_string.bytes());
//! let bytes_string = &bytes_string;
//! println(bytes_string.bytes());
//!
//! // OsString
//! let bytes_os_string: OsString = OsString::from(bytes_str);
//! println(bytes_os_string.as_bytes());
//! let bytes_os_string: &OsString = &bytes_os_string;
//! println(bytes_os_string.as_bytes());
//!
//! // OsStr
//! let bytes_os_str: &OsStr = OsStr::from_bytes(bytes_slice);
//! println(bytes_os_str.as_bytes());
//!
//! // Box<[u8]>
//! let boxed_slice: Box<[u8]> = Box::new([72, 101, 108, 108, 111, 0, 255]);
//! println(boxed_slice.iter());
//! println(&mut boxed_slice.iter());
//!
//! // std::io::Cursor<Vec<u8>>
//! let cursor = Cursor::new(vec![72, 101, 108, 108, 111, 0, 255]);
//! let bytes_from_cursor: Vec<u8> = cursor.into_inner();
//! println(&bytes_from_cursor);
//! println(bytes_from_cursor);
//!
//! // std::collections::VecDeque<u8>
//! let mut vec_deque = VecDeque::new();
//! vec_deque.push_back(72);
//! vec_deque.push_back(101);
//! vec_deque.push_back(108);
//! vec_deque.push_back(108);
//! vec_deque.push_back(111);
//! vec_deque.push_back(0);
//! vec_deque.push_back(255);
//! println(&vec_deque);
//! println(vec_deque);
//!
//! // Cow<[u8]>
//! let cow_slice: Cow<[u8]> = Cow::Borrowed(&[72, 101, 108, 108, 111, 0, 255]);
//! println(cow_slice.iter());
//! let cow_slice: Cow<[u8]> = Cow::Owned(vec![72, 101, 108, 108, 111, 0, 255]);
//! println(cow_slice.iter());
//!
//! // Arc<Vec<u8>>
//! let arc_slice = Arc::new(vec![72, 101, 108, 108, 111, 0, 255]);
//! println(arc_slice.iter());
//!
//! // Rc<Vec<u8>>
//! let rc_slice = Rc::new(vec![72, 101, 108, 108, 111, 0, 255]);
//! println(rc_slice.iter());
//! ```
use Borrow;
use ;
/// A helper function to show bytes without explicitly creating a Printer struct.
///
/// `show_bytes(bytes)` is equivalent to `Printer::new(QuoteStyle::Double).into_string(bytes)`.
/// Maintains an internal state describing how to display a byte array.
///
/// It can write to an arbitrary `std::fmt::Write` implementation using the
/// method `Printer::write_to`.
/// Indicates how, if at all, the printer should quote the byte string.
///
/// A printer's quoting style is chosen by passing a `QuoteStyle` to `Printer::new`.
/// The choice of quoting style affects which characters are escaped.
/// Returns `Quotes::None`.
/// Returns a printer that doesn't quote its output.
///
/// This is equivalent to `Printer::new(QuoteStyle::None)`.