From 2e4f293cee28cd5fb62ed5e8c95472764f5f5143 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 14 May 2023 17:00:17 +0200 Subject: refactor: make the TagStart name function error type TagStartError --- src/tagged.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/tagged.rs') diff --git a/src/tagged.rs b/src/tagged.rs index 1fca458..eada376 100644 --- a/src/tagged.rs +++ b/src/tagged.rs @@ -43,9 +43,9 @@ impl<'a> TagStart<'a> /// /// # Errors /// Returns `Err` if the name is not valid UTF-8. - pub fn name(&self) -> Result<&str, Utf8Error> + pub fn name(&self) -> Result<&str, TagStartError> { - std::str::from_utf8(self.name_bytes()) + std::str::from_utf8(self.name_bytes()).map_err(TagStartError::NameNotUTF8) } /// Returns the name as bytes. @@ -101,4 +101,8 @@ pub enum TagStartError /// Invalid attribute. #[error("Invalid attribute")] InvalidAttribute(#[from] AttributeError), + + /// Name is not valid UTF-8. + #[error("Name is not valid UTF-8")] + NameNotUTF8(#[source] Utf8Error), } -- cgit v1.2.3-18-g5258