Skip to content

Commit

Permalink
Remove excessive BufRead constraint
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Alley <dalley@redhat.com>
  • Loading branch information
Mingun and dralley committed Jul 9, 2022
1 parent 5e6d045 commit ae458cb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/events/attributes.rs
Expand Up @@ -9,7 +9,7 @@ use crate::reader::{is_whitespace, Reader};
use crate::utils::{write_byte_string, write_cow_string, Bytes};
use std::fmt::{self, Debug, Display, Formatter};
use std::iter::FusedIterator;
use std::{borrow::Cow, collections::HashMap, io::BufRead, ops::Range};
use std::{borrow::Cow, collections::HashMap, ops::Range};

/// A struct representing a key/value XML attribute.
///
Expand Down Expand Up @@ -81,7 +81,7 @@ impl<'a> Attribute<'a> {
///
/// [`unescaped_value()`]: #method.unescaped_value
/// [`Reader::decode()`]: ../../reader/struct.Reader.html#method.decode
pub fn unescape_and_decode_value<B: BufRead>(&self, reader: &Reader<B>) -> XmlResult<String> {
pub fn unescape_and_decode_value<B>(&self, reader: &Reader<B>) -> XmlResult<String> {
self.do_unescape_and_decode_value(reader, None)
}

Expand All @@ -99,7 +99,7 @@ impl<'a> Attribute<'a> {
/// # Pre-condition
///
/// The keys and values of `custom_entities`, if any, must be valid UTF-8.
pub fn unescape_and_decode_value_with_custom_entities<B: BufRead>(
pub fn unescape_and_decode_value_with_custom_entities<B>(
&self,
reader: &Reader<B>,
custom_entities: &HashMap<Vec<u8>, Vec<u8>>,
Expand All @@ -108,7 +108,7 @@ impl<'a> Attribute<'a> {
}

/// The keys and values of `custom_entities`, if any, must be valid UTF-8.
fn do_unescape_and_decode_value<B: BufRead>(
fn do_unescape_and_decode_value<B>(
&self,
reader: &Reader<B>,
custom_entities: Option<&HashMap<Vec<u8>, Vec<u8>>>,
Expand Down
7 changes: 3 additions & 4 deletions src/events/mod.rs
Expand Up @@ -39,7 +39,6 @@ use encoding_rs::Encoding;
use std::borrow::Cow;
use std::collections::HashMap;
use std::fmt::{self, Debug, Formatter};
use std::io::BufRead;
use std::ops::Deref;
use std::str::from_utf8;

Expand Down Expand Up @@ -755,7 +754,7 @@ impl<'a> BytesText<'a> {
/// it might be wiser to manually use
/// 1. BytesText::unescaped()
/// 2. Reader::decode(...)
pub fn unescape_and_decode<B: BufRead>(&self, reader: &Reader<B>) -> Result<String> {
pub fn unescape_and_decode<B>(&self, reader: &Reader<B>) -> Result<String> {
self.do_unescape_and_decode_with_custom_entities(reader, None)
}

Expand All @@ -769,15 +768,15 @@ impl<'a> BytesText<'a> {
/// # Pre-condition
///
/// The keys and values of `custom_entities`, if any, must be valid UTF-8.
pub fn unescape_and_decode_with_custom_entities<B: BufRead>(
pub fn unescape_and_decode_with_custom_entities<B>(
&self,
reader: &Reader<B>,
custom_entities: &HashMap<Vec<u8>, Vec<u8>>,
) -> Result<String> {
self.do_unescape_and_decode_with_custom_entities(reader, Some(custom_entities))
}

fn do_unescape_and_decode_with_custom_entities<B: BufRead>(
fn do_unescape_and_decode_with_custom_entities<B>(
&self,
reader: &Reader<B>,
custom_entities: Option<&HashMap<Vec<u8>, Vec<u8>>>,
Expand Down
12 changes: 6 additions & 6 deletions src/reader.rs
Expand Up @@ -107,7 +107,7 @@ impl EncodingRef {

/// A low level encoding-agnostic XML event reader.
///
/// Consumes a `BufRead` and streams XML `Event`s.
/// Consumes bytes and streams XML [`Event`]s.
///
/// # Examples
///
Expand Down Expand Up @@ -144,7 +144,7 @@ impl EncodingRef {
/// }
/// ```
#[derive(Clone)]
pub struct Reader<R: BufRead> {
pub struct Reader<R> {
/// reader
pub(crate) reader: R,
/// current buffer position, useful for debugging errors
Expand Down Expand Up @@ -198,8 +198,8 @@ pub struct Reader<R: BufRead> {
}

/// Builder methods
impl<R: BufRead> Reader<R> {
/// Creates a `Reader` that reads from a reader implementing `BufRead`.
impl<R> Reader<R> {
/// Creates a `Reader` that reads from a given reader.
pub fn from_reader(reader: R) -> Self {
Self {
reader,
Expand Down Expand Up @@ -323,7 +323,7 @@ impl<R: BufRead> Reader<R> {
}

/// Getters
impl<R: BufRead> Reader<R> {
impl<R> Reader<R> {
/// Consumes `Reader` returning the underlying reader
///
/// Can be used to compute line and column of a parsing error position
Expand Down Expand Up @@ -761,7 +761,7 @@ impl<R: BufRead> Reader<R> {
}

/// Private methods
impl<R: BufRead> Reader<R> {
impl<R> Reader<R> {
/// Read text into the given buffer, and return an event that borrows from
/// either that buffer or from the input itself, based on the type of the
/// reader.
Expand Down

0 comments on commit ae458cb

Please sign in to comment.