Skip to content

Commit

Permalink
Add accessors to underlying reader: .get_ref() and .get_mut()
Browse files Browse the repository at this point in the history
into_underlying_reader() renamed to into_inner() for consistency with standard Rust readers

Implements #358
  • Loading branch information
Mingun committed May 7, 2022
1 parent 6a3fd90 commit 1d9af37
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
- fix: do not unescape CDATA content because it never escaped by design.
CDATA event data now represented by its own `BytesCData` type
([quick-xml#311](/~https://github.com/tafia/quick-xml/issues/311))
- feat: add `Reader::get_ref()` and `Reader::get_mut()`, rename
`Reader::into_underlying_reader()` to `Reader::into_inner()`

## 0.23.0-alpha3

Expand Down
14 changes: 12 additions & 2 deletions src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ impl<R: BufRead> Reader<R> {
///
/// fn into_line_and_column(reader: Reader<Cursor<&[u8]>>) -> (usize, usize) {
/// let end_pos = reader.buffer_position();
/// let mut cursor = reader.into_underlying_reader();
/// let mut cursor = reader.into_inner();
/// let s = String::from_utf8(cursor.into_inner()[0..end_pos].to_owned())
/// .expect("can't make a string");
/// let mut line = 1;
Expand Down Expand Up @@ -868,9 +868,19 @@ impl<R: BufRead> Reader<R> {
/// buf.clear();
/// }
/// ```
pub fn into_underlying_reader(self) -> R {
pub fn into_inner(self) -> R {
self.reader
}

/// Gets a reference to the underlying reader.
pub fn get_ref(&self) -> &R {
&self.reader
}

/// Gets a mutable reference to the underlying reader.
pub fn get_mut(&mut self) -> &mut R {
&mut self.reader
}
}

impl Reader<BufReader<File>> {
Expand Down

0 comments on commit 1d9af37

Please sign in to comment.