|
18 | 18 | //!
|
19 | 19 | //! # fn foo() -> io::Result<()> {
|
20 | 20 | //! let bytes_with_colors = b"\x1b[32mfoo\x1b[m bar";
|
21 |
| -//! let plain_bytes = strip_ansi_escapes::strip(&bytes_with_colors)?; |
| 21 | +//! let plain_bytes = strip_ansi_escapes::strip(&bytes_with_colors); |
22 | 22 | //! io::stdout().write_all(&plain_bytes)?;
|
23 | 23 | //! # Ok(())
|
24 | 24 | //! # }
|
@@ -59,14 +59,18 @@ where
|
59 | 59 | /// See [the module documentation][mod] for an example.
|
60 | 60 | ///
|
61 | 61 | /// [mod]: index.html
|
62 |
| -pub fn strip<T>(data: T) -> io::Result<Vec<u8>> |
| 62 | +pub fn strip<T>(data: T) -> Vec<u8> |
63 | 63 | where
|
64 | 64 | T: AsRef<[u8]>,
|
65 | 65 | {
|
66 |
| - let c = Cursor::new(Vec::new()); |
67 |
| - let mut writer = Writer::new(c); |
68 |
| - writer.write_all(data.as_ref())?; |
69 |
| - Ok(writer.into_inner()?.into_inner()) |
| 66 | + fn strip_impl(data: &[u8]) -> io::Result<Vec<u8>> { |
| 67 | + let c = Cursor::new(Vec::new()); |
| 68 | + let mut writer = Writer::new(c); |
| 69 | + writer.write_all(data.as_ref())?; |
| 70 | + Ok(writer.into_inner()?.into_inner()) |
| 71 | + } |
| 72 | + |
| 73 | + strip_impl(data.as_ref()).expect("writing to a Cursor<Vec<u8>> cannot fail") |
70 | 74 | }
|
71 | 75 |
|
72 | 76 | struct Performer<W>
|
@@ -162,7 +166,7 @@ mod tests {
|
162 | 166 | use super::*;
|
163 | 167 |
|
164 | 168 | fn assert_parsed(input: &[u8], expected: &[u8]) {
|
165 |
| - let bytes = strip(input).expect("Failed to strip escapes"); |
| 169 | + let bytes = strip(input); |
166 | 170 | assert_eq!(bytes, expected);
|
167 | 171 | }
|
168 | 172 |
|
|
0 commit comments