diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 2 | ||||
-rw-r--r-- | src/reader.rs | 24 | ||||
-rw-r--r-- | src/tokenizer.rs | 8 |
3 files changed, 17 insertions, 17 deletions
@@ -19,5 +19,5 @@ pub use utils::State as InternalState; pub use emitter::{Attribute, DefaultEmitter, Doctype, Emitter, EndTag, StartTag, Token}; pub use error::Error; pub use never::Never; -pub use reader::{BufReadReader, Readable, Reader, StringReader}; +pub use reader::{BufReadReader, IntoReader, Reader, StringReader}; pub use tokenizer::{InfallibleTokenizer, State, Tokenizer}; diff --git a/src/reader.rs b/src/reader.rs index eb2b479..6067c47 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -31,18 +31,18 @@ pub trait Reader { /// /// For example, any utf8-string can be converted into a `StringReader`, such that /// `Tokenizer::new("mystring")` and `Tokenizer::new(&String::new("foo"))` work. -pub trait Readable<'a> { - /// The reader type to which this type should be converted. +pub trait IntoReader<'a> { + /// The reader type into which this type should be converted. type Reader: Reader + 'a; - /// Convert self to some sort of reader. - fn to_reader(self) -> Self::Reader; + /// Convert self into some sort of reader. + fn into_reader(self) -> Self::Reader; } -impl<'a, R: 'a + Reader> Readable<'a> for R { +impl<'a, R: 'a + Reader> IntoReader<'a> for R { type Reader = Self; - fn to_reader(self) -> Self::Reader { + fn into_reader(self) -> Self::Reader { self } } @@ -120,18 +120,18 @@ impl<'a> Reader for StringReader<'a> { } } -impl<'a> Readable<'a> for &'a str { +impl<'a> IntoReader<'a> for &'a str { type Reader = StringReader<'a>; - fn to_reader(self) -> Self::Reader { + fn into_reader(self) -> Self::Reader { StringReader::new(self) } } -impl<'a> Readable<'a> for &'a String { +impl<'a> IntoReader<'a> for &'a String { type Reader = StringReader<'a>; - fn to_reader(self) -> Self::Reader { + fn into_reader(self) -> Self::Reader { StringReader::new(self.as_str()) } } @@ -225,10 +225,10 @@ impl<R: BufRead> Reader for BufReadReader<R> { } } -impl<'a, R: Read + 'a> Readable<'a> for BufReader<R> { +impl<'a, R: Read + 'a> IntoReader<'a> for BufReader<R> { type Reader = BufReadReader<BufReader<R>>; - fn to_reader(self) -> Self::Reader { + fn into_reader(self) -> Self::Reader { BufReadReader::new(self) } } diff --git a/src/tokenizer.rs b/src/tokenizer.rs index ee8f893..b2d4b53 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -4,7 +4,7 @@ use crate::machine; use crate::utils::{ control_pat, noncharacter_pat, surrogate_pat, ControlToken, State as InternalState, }; -use crate::{DefaultEmitter, Emitter, Error, Never, Readable, Reader}; +use crate::{DefaultEmitter, Emitter, Error, IntoReader, Never, Reader}; // this is a stack that can hold 0 to 2 Ts #[derive(Debug, Default, Clone, Copy)] @@ -49,7 +49,7 @@ impl<R: Reader> Tokenizer<R> { /// /// Patches are welcome for providing an efficient implementation over async streams, /// iterators, files, etc, as long as any dependencies come behind featureflags. - pub fn new<'a, S: Readable<'a, Reader = R>>(input: S) -> Self { + pub fn new<'a, S: IntoReader<'a, Reader = R>>(input: S) -> Self { Tokenizer::<S::Reader>::new_with_emitter(input, DefaultEmitter::default()) } } @@ -93,14 +93,14 @@ impl<R: Reader, E: Emitter<R>> Tokenizer<R, E> { /// /// Use this method over [`Tokenizer::new`] when you want to have more control over string allocation for /// tokens. - pub fn new_with_emitter<'a, S: Readable<'a, Reader = R>>(input: S, emitter: E) -> Self { + pub fn new_with_emitter<'a, S: IntoReader<'a, Reader = R>>(input: S, emitter: E) -> Self { Tokenizer { eof: false, state: InternalState::Data, emitter, temporary_buffer: String::new(), to_reconsume: Stack2::default(), - reader: input.to_reader(), + reader: input.into_reader(), character_reference_code: 0, return_state: None, } |