Skip to content

Commit 1186517

Browse files
authored
Remove InfallibleTokenizer (#102)
* Remove InfallibleTokenizer InfallibleTokenizer and Tokenizer::infallible were added as shortcuts for when the underlying input cannot fail, to make iteration slightly more ergonomic. In recent Rust versions it's possible to run `for Ok(token) in ...`, which makes this useless. * remove impl * fix * fix doc * fix benchmarks * link pr
1 parent 0530ebd commit 1186517

File tree

8 files changed

+22
-35
lines changed

8 files changed

+22
-35
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# 0.7.0
2+
3+
- Removal of `Tokenizer.infallible()`. Use `for Ok(token) in Tokenizer::new()` instead. [PR 102](https://github.com/untitaker/html5gum/pull/102)
4+
- Add more convenience functions to `tree-builder` feature, equivalent to `html5ever::driver`. [PR 101](https://github.com/untitaker/html5gum/pull/101)
5+
6+
# 0.6.1
7+
8+
- Fix a bug where html5gum would interpret tags inside of `<script>`. [PR 98](https://github.com/untitaker/html5gum/pull/98)
9+
- Restructured the crate slightly, though there _should_ not be any breaking changes. [PR 99](https://github.com/untitaker/html5gum/pull/99)
10+
- Added a way to integrate with `scraper` crate and the `html5ever` tree builder, see `examples/scraper.rs`.
11+
12+
# Before 0.6.1
13+
14+
Who knows...

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ test-generator = "0.3.0"
1919
serde_bytes = "0.11.5"
2020
glob = "0.3.0"
2121
libtest-mimic = "0.8.1"
22-
iai = "0.1.1"
22+
# https://github.com/bheisler/iai/issues/34
23+
iai = { git = "https://github.com/sigaloid/iai", rev = "6c83e942" }
2324
# required for examples/scraper.rs
2425
scraper = "0.20.0"
2526
argh = "0.1.12"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use html5gum::{Tokenizer, Token};
1212
let html = "<title >hello world</title>";
1313
let mut new_html = String::new();
1414

15-
for token in Tokenizer::new(html).infallible() {
15+
for Ok(token) in Tokenizer::new(html) {
1616
match token {
1717
Token::StartTag(tag) => {
1818
write!(new_html, "<{}>", String::from_utf8_lossy(&tag.name)).unwrap();

benches/patterns.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use html5gum::Tokenizer;
44

55
fn pattern(pattern: &str, i: usize) {
66
let s: String = black_box((0..i).map(|_| pattern).collect());
7-
for _ in Tokenizer::new(&s).infallible() {}
7+
for Ok(_) in Tokenizer::new(&s) {}
88
}
99

1010
macro_rules! pattern_tests {

src/emitters/callback.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@
2929
//! });
3030
//!
3131
//! let input = r#"<h1><span class=hello>Hello</span> world!</h1>"#;
32-
//! let text_fragments = Tokenizer::new_with_emitter(input, emitter)
33-
//! .infallible()
34-
//! .collect::<Vec<_>>();
32+
//! let Ok(text_fragments) = Tokenizer::new_with_emitter(input, emitter)
33+
//! .collect::<Result<Vec<_>, _>>();
3534
//!
3635
//! assert_eq!(text_fragments, vec![b"Hello".to_vec()]);
3736
//! ```

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,4 @@ pub use error::Error;
6161
pub use htmlstring::HtmlString;
6262
pub use reader::{IoReader, Readable, Reader, StringReader};
6363
pub use state::State;
64-
pub use tokenizer::{InfallibleTokenizer, Tokenizer};
64+
pub use tokenizer::Tokenizer;

src/reader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl<'a, R: 'a + Reader> Readable<'a> for R {
126126
/// let html = "<title >hello world</title>";
127127
/// let mut new_html = String::new();
128128
///
129-
/// for token in Tokenizer::new(html).infallible() {
129+
/// for Ok(token) in Tokenizer::new(html) {
130130
/// match token {
131131
/// Token::StartTag(tag) => {
132132
/// write!(new_html, "<{}>", String::from_utf8_lossy(&tag.name)).unwrap();

src/tokenizer.rs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -123,30 +123,3 @@ impl<R: Reader, E: Emitter> Iterator for Tokenizer<R, E> {
123123
}
124124
}
125125
}
126-
127-
/// A kind of tokenizer that directly yields tokens when used as an iterator, so `Token` instead of
128-
/// `Result<Token, _>`.
129-
///
130-
/// This is the return value of [`Tokenizer::infallible`].
131-
#[derive(Debug)]
132-
pub struct InfallibleTokenizer<R: Reader<Error = Infallible>, E: Emitter>(Tokenizer<R, E>);
133-
134-
impl<R: Reader<Error = Infallible>, E: Emitter> Tokenizer<R, E> {
135-
/// Statically assert that this iterator is infallible.
136-
///
137-
/// Call this to get rid of error handling when parsing HTML from strings.
138-
pub fn infallible(self) -> InfallibleTokenizer<R, E> {
139-
InfallibleTokenizer(self)
140-
}
141-
}
142-
143-
impl<R: Reader<Error = Infallible>, E: Emitter> Iterator for InfallibleTokenizer<R, E> {
144-
type Item = E::Token;
145-
146-
fn next(&mut self) -> Option<Self::Item> {
147-
match self.0.next()? {
148-
Ok(token) => Some(token),
149-
Err(e) => match e {},
150-
}
151-
}
152-
}

0 commit comments

Comments
 (0)