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 29a22a5 commit 8ea9382
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion bench/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ fn sentences(c: &mut Criterion) {
fn byte_lines(c: &mut Criterion) {
use bstr::io::BufReadExt;

let corpus = SUBTITLE_EN_HUGE;
let mut corpus = SUBTITLE_EN_HUGE;
define(c, "bstr/for_byte_line", "ascii", corpus, move |b| {
b.iter(|| {
let mut count = 0;
Expand Down
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 8ea9382

Please sign in to comment.