From e92f0c62a20c105cc9853c75f88c78bbe16d7193 Mon Sep 17 00:00:00 2001 From: DarkCat09 Date: Thu, 1 Aug 2024 10:29:34 +0400 Subject: [PATCH] feat: return LibError from Response::mime(&Self) --- src/error.rs | 8 ++++++++ src/response.rs | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/error.rs b/src/error.rs index 330dde5..d76e55d 100644 --- a/src/error.rs +++ b/src/error.rs @@ -3,6 +3,7 @@ pub enum LibError { InvalidUrlError(InvalidUrl), StatusOutOfRange(u8), MessageNotUtf8(std::string::FromUtf8Error), + InvalidMime(mime::FromStrError), } impl From for LibError { @@ -40,6 +41,13 @@ impl From for LibError { } } +impl From for LibError { + #[inline] + fn from(err: mime::FromStrError) -> Self { + Self::InvalidMime(err) + } +} + pub enum InvalidUrl { ParseError(url::ParseError), SchemeNotGemini, diff --git a/src/response.rs b/src/response.rs index 6b2cc8f..ad7bc93 100644 --- a/src/response.rs +++ b/src/response.rs @@ -1,4 +1,4 @@ -use crate::status::Status; +use crate::{status::Status, LibError}; type BodyStream = tokio_rustls::client::TlsStream; @@ -25,8 +25,8 @@ impl Response { &self.message } - pub fn mime(self: &Self) -> Result { - self.message.parse() + pub fn mime(self: &Self) -> Result { + self.message.parse().map_err(|e| LibError::InvalidMime(e)) } pub fn body(self: &Self) -> &BodyStream {