Skip to content

Commit 5e24faf

Browse files
committed
make strip() no longer return errors (#9)
Writing to a `Cursor<Vec<u8>>` can never fail.
1 parent f42c49e commit 5e24faf

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::io::{self, Write};
1616

1717
fn work() -> io::Result<()> {
1818
let bytes_with_colors = b"\x1b[32mfoo\x1b[m bar";
19-
let plain_bytes = strip_ansi_escapes::strip(&bytes_with_colors)?;
19+
let plain_bytes = strip_ansi_escapes::strip(&bytes_with_colors);
2020
io::stdout().write_all(&plain_bytes)?;
2121
Ok(())
2222
}

src/lib.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
//!
1919
//! # fn foo() -> io::Result<()> {
2020
//! 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);
2222
//! io::stdout().write_all(&plain_bytes)?;
2323
//! # Ok(())
2424
//! # }
@@ -59,14 +59,18 @@ where
5959
/// See [the module documentation][mod] for an example.
6060
///
6161
/// [mod]: index.html
62-
pub fn strip<T>(data: T) -> io::Result<Vec<u8>>
62+
pub fn strip<T>(data: T) -> Vec<u8>
6363
where
6464
T: AsRef<[u8]>,
6565
{
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")
7074
}
7175

7276
struct Performer<W>
@@ -162,7 +166,7 @@ mod tests {
162166
use super::*;
163167

164168
fn assert_parsed(input: &[u8], expected: &[u8]) {
165-
let bytes = strip(input).expect("Failed to strip escapes");
169+
let bytes = strip(input);
166170
assert_eq!(bytes, expected);
167171
}
168172

0 commit comments

Comments
 (0)