Skip to content

Commit

Permalink
BREAKING: change methods on BufReadExt to take '&mut self'
Browse files Browse the repository at this point in the history
Previously, they consumed 'self', but there is no particular reason why
they need to do that. Instead, we can borrow self mutably.

The two methods that return iterators do continue to consume 'self'
though, which matches the style used by 'std' for 'BufRead'.
  • Loading branch information
BurntSushi committed Jul 11, 2022
1 parent 8a29d32 commit 741e17b
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub trait BufReadExt: io::BufRead {
/// use bstr::io::BufReadExt;
///
/// # fn example() -> Result<(), io::Error> {
/// let cursor = io::Cursor::new(b"lorem\nipsum\r\ndolor");
/// let mut cursor = io::Cursor::new(b"lorem\nipsum\r\ndolor");
///
/// let mut lines = vec![];
/// for result in cursor.byte_lines() {
Expand Down Expand Up @@ -80,7 +80,7 @@ pub trait BufReadExt: io::BufRead {
/// use bstr::io::BufReadExt;
///
/// # fn example() -> Result<(), io::Error> {
/// let cursor = io::Cursor::new(b"lorem\x00ipsum\x00dolor");
/// let mut cursor = io::Cursor::new(b"lorem\x00ipsum\x00dolor");
///
/// let mut records = vec![];
/// for result in cursor.byte_records(b'\x00') {
Expand Down Expand Up @@ -123,7 +123,7 @@ pub trait BufReadExt: io::BufRead {
/// use bstr::io::BufReadExt;
///
/// # fn example() -> Result<(), io::Error> {
/// let cursor = io::Cursor::new(b"lorem\nipsum\r\ndolor");
/// let mut cursor = io::Cursor::new(b"lorem\nipsum\r\ndolor");
///
/// let mut lines = vec![];
/// cursor.for_byte_line(|line| {
Expand All @@ -136,7 +136,7 @@ pub trait BufReadExt: io::BufRead {
/// assert_eq!(lines[2], "dolor".as_bytes());
/// # Ok(()) }; example().unwrap()
/// ```
fn for_byte_line<F>(self, mut for_each_line: F) -> io::Result<()>
fn for_byte_line<F>(&mut self, mut for_each_line: F) -> io::Result<()>
where
Self: Sized,
F: FnMut(&[u8]) -> io::Result<bool>,
Expand Down Expand Up @@ -170,7 +170,7 @@ pub trait BufReadExt: io::BufRead {
/// use bstr::io::BufReadExt;
///
/// # fn example() -> Result<(), io::Error> {
/// let cursor = io::Cursor::new(b"lorem\x00ipsum\x00dolor");
/// let mut cursor = io::Cursor::new(b"lorem\x00ipsum\x00dolor");
///
/// let mut records = vec![];
/// cursor.for_byte_record(b'\x00', |record| {
Expand All @@ -184,7 +184,7 @@ pub trait BufReadExt: io::BufRead {
/// # Ok(()) }; example().unwrap()
/// ```
fn for_byte_record<F>(
self,
&mut self,
terminator: u8,
mut for_each_record: F,
) -> io::Result<()>
Expand Down Expand Up @@ -224,7 +224,7 @@ pub trait BufReadExt: io::BufRead {
/// use bstr::io::BufReadExt;
///
/// # fn example() -> Result<(), io::Error> {
/// let cursor = io::Cursor::new(b"lorem\nipsum\r\ndolor");
/// let mut cursor = io::Cursor::new(b"lorem\nipsum\r\ndolor");
///
/// let mut lines = vec![];
/// cursor.for_byte_line_with_terminator(|line| {
Expand All @@ -238,7 +238,7 @@ pub trait BufReadExt: io::BufRead {
/// # Ok(()) }; example().unwrap()
/// ```
fn for_byte_line_with_terminator<F>(
self,
&mut self,
for_each_line: F,
) -> io::Result<()>
where
Expand Down Expand Up @@ -273,7 +273,7 @@ pub trait BufReadExt: io::BufRead {
/// use bstr::{io::BufReadExt, B};
///
/// # fn example() -> Result<(), io::Error> {
/// let cursor = io::Cursor::new(b"lorem\x00ipsum\x00dolor");
/// let mut cursor = io::Cursor::new(b"lorem\x00ipsum\x00dolor");
///
/// let mut records = vec![];
/// cursor.for_byte_record_with_terminator(b'\x00', |record| {
Expand All @@ -287,7 +287,7 @@ pub trait BufReadExt: io::BufRead {
/// # Ok(()) }; example().unwrap()
/// ```
fn for_byte_record_with_terminator<F>(
mut self,
&mut self,
terminator: u8,
mut for_each_record: F,
) -> io::Result<()>
Expand Down

0 comments on commit 741e17b

Please sign in to comment.