From 04e6cbe44bb7a388bd61d1c9cfe4c618eb3b0e29 Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Sun, 23 Jan 2022 14:47:20 +0100 Subject: [PATCH] remove never type in favor of infallible --- src/lib.rs | 2 -- src/never.rs | 24 ------------------------ src/reader.rs | 4 ++-- src/tokenizer.rs | 10 ++++++---- 4 files changed, 8 insertions(+), 32 deletions(-) delete mode 100644 src/never.rs diff --git a/src/lib.rs b/src/lib.rs index 87d174a..4014522 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,7 +14,6 @@ mod entities; mod error; mod machine; mod machine_helper; -mod never; mod read_helper; mod reader; mod tokenizer; @@ -25,6 +24,5 @@ pub mod testutils; pub use emitter::{DefaultEmitter, Doctype, Emitter, EndTag, StartTag, Token}; pub use error::Error; -pub use never::Never; pub use reader::{IoReader, Readable, Reader, StringReader}; pub use tokenizer::{InfallibleTokenizer, Tokenizer}; diff --git a/src/never.rs b/src/never.rs deleted file mode 100644 index cb7d11c..0000000 --- a/src/never.rs +++ /dev/null @@ -1,24 +0,0 @@ -use std::error; -use std::fmt; - -/// Definition of an empty enum. -/// -/// This is used as the error type in situations where there can't be an error. A `Result` -/// can be safely unwrapped and the `unwrap()` may be optimized away entirely. -/// -/// This error is typically encountered when attempting to get tokens from the `Tokenizer`. Call -/// [`crate::Tokenizer::infallible`] if you wish to avoid unwrapping those results yourself. -pub enum Never {} - -impl fmt::Display for Never { - fn fmt(&self, _: &mut fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { - match *self {} - } -} -impl fmt::Debug for Never { - fn fmt(&self, _: &mut fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { - match *self {} - } -} - -impl error::Error for Never {} diff --git a/src/reader.rs b/src/reader.rs index 3deaeea..99dc71b 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -1,5 +1,5 @@ -use crate::Never; use std::cmp::min; +use std::convert::Infallible; use std::fs::File; use std::io::{self, Read}; @@ -152,7 +152,7 @@ impl<'a> StringReader<'a> { } impl<'a> Reader for StringReader<'a> { - type Error = Never; + type Error = Infallible; fn read_byte(&mut self) -> Result, Self::Error> { if self.input.is_empty() { diff --git a/src/tokenizer.rs b/src/tokenizer.rs index df2424a..241b878 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -1,9 +1,11 @@ +use std::convert::Infallible; + use crate::char_validator::CharValidator; use crate::machine; use crate::machine_helper::MachineHelper; use crate::read_helper::ReadHelper; use crate::utils::{ControlToken, State}; -use crate::{DefaultEmitter, Emitter, Never, Readable, Reader}; +use crate::{DefaultEmitter, Emitter, Readable, Reader}; /// A HTML tokenizer. See crate-level docs for basic usage. pub struct Tokenizer { @@ -96,9 +98,9 @@ impl Iterator for Tokenizer { /// `Result`. /// /// This is the return value of [`Tokenizer::infallible`]. -pub struct InfallibleTokenizer, E: Emitter>(Tokenizer); +pub struct InfallibleTokenizer, E: Emitter>(Tokenizer); -impl, E: Emitter> Tokenizer { +impl, E: Emitter> Tokenizer { /// Statically assert that this iterator is infallible. /// /// Call this to get rid of error handling when parsing HTML from strings. @@ -107,7 +109,7 @@ impl, E: Emitter> Tokenizer { } } -impl, E: Emitter> Iterator for InfallibleTokenizer { +impl, E: Emitter> Iterator for InfallibleTokenizer { type Item = E::Token; fn next(&mut self) -> Option {