mirror of
https://github.com/YGGverse/ggemini.git
synced 2026-03-31 17:15:31 +00:00
change Mime struct, implement Display trait
This commit is contained in:
parent
09b2c626a3
commit
d3133f50f7
1 changed files with 16 additions and 3 deletions
|
|
@ -6,11 +6,17 @@ pub use error::Error;
|
|||
use glib::{GString, Regex, RegexCompileFlags, RegexMatchFlags};
|
||||
|
||||
/// https://geminiprotocol.net/docs/gemtext-specification.gmi#media-type-parameters
|
||||
pub struct Mime {
|
||||
pub value: String,
|
||||
pub struct Mime(String);
|
||||
|
||||
impl std::fmt::Display for Mime {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
write!(f, "{}", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Mime {
|
||||
// Constructors
|
||||
|
||||
/// Create new `Self` from UTF-8 buffer (that includes **header**)
|
||||
/// * return `None` for non 2* [status codes](https://geminiprotocol.net/docs/protocol-specification.gmi#status-codes)
|
||||
pub fn from_utf8(buffer: &[u8]) -> Result<Option<Self>, Error> {
|
||||
|
|
@ -37,10 +43,17 @@ impl Mime {
|
|||
return Ok(None);
|
||||
}
|
||||
match parse(subject) {
|
||||
Some(value) => Ok(Some(Self { value })),
|
||||
Some(value) => Ok(Some(Self(value))),
|
||||
None => Err(Error::Undefined),
|
||||
}
|
||||
}
|
||||
|
||||
// Getters
|
||||
|
||||
/// Get `Self` as `&str`
|
||||
pub fn as_str(&self) -> &str {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
/// Extract MIME type from from string that includes **header**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue