diff --git a/src/client/connection/response/meta/mime.rs b/src/client/connection/response/meta/mime.rs index 9593e9c..2b15d32 100644 --- a/src/client/connection/response/meta/mime.rs +++ b/src/client/connection/response/meta/mime.rs @@ -3,7 +3,7 @@ pub mod error; pub use error::Error; -use glib::{GString, Regex, RegexCompileFlags, RegexMatchFlags}; +use glib::{Regex, RegexCompileFlags, RegexMatchFlags}; /// MIME type holder for `Response` (by [Gemtext specification](https://geminiprotocol.net/docs/gemtext-specification.gmi#media-type-parameters)) /// * the value stored in lowercase @@ -29,22 +29,22 @@ impl Mime { // Parse meta bytes only match buffer.get(..if len > MAX_LEN { MAX_LEN } else { len }) { - Some(value) => match GString::from_utf8(value.into()) { - Ok(string) => Self::from_string(&string), + Some(utf8) => match std::str::from_utf8(utf8) { + Ok(s) => Self::from_string(s), Err(e) => Err(Error::Decode(e)), }, None => Err(Error::Protocol), } } - /// Create new `Self` from string that includes **header** + /// Create new `Self` from `str::str` that includes **header** /// * return `None` for non 2* [status codes](https://geminiprotocol.net/docs/protocol-specification.gmi#status-codes) - pub fn from_string(subject: &str) -> Result, Error> { - if !subject.starts_with("2") { + pub fn from_string(s: &str) -> Result, Error> { + if !s.starts_with("2") { return Ok(None); } - match parse(subject) { - Some(value) => Ok(Some(Self(value.to_lowercase()))), + match parse(s) { + Some(v) => Ok(Some(Self(v.to_lowercase()))), None => Err(Error::Undefined), } } @@ -58,10 +58,10 @@ impl Mime { } /// Extract MIME type from from string that includes **header** -pub fn parse(value: &str) -> Option { +pub fn parse(s: &str) -> Option { Regex::split_simple( r"^2\d{1}\s([^\/]+\/[^\s;]+)", - value, + s, RegexCompileFlags::DEFAULT, RegexMatchFlags::DEFAULT, ) diff --git a/src/client/connection/response/meta/mime/error.rs b/src/client/connection/response/meta/mime/error.rs index 9ea72ba..5b68dbc 100644 --- a/src/client/connection/response/meta/mime/error.rs +++ b/src/client/connection/response/meta/mime/error.rs @@ -1,14 +1,12 @@ -use std::fmt::{Display, Formatter, Result}; - #[derive(Debug)] pub enum Error { - Decode(std::string::FromUtf8Error), + Decode(std::str::Utf8Error), Protocol, Undefined, } -impl Display for Error { - fn fmt(&self, f: &mut Formatter) -> Result { +impl std::fmt::Display for Error { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { match self { Self::Decode(e) => { write!(f, "Decode error: {e}")