mirror of
https://github.com/YGGverse/ggemini.git
synced 2026-04-01 01:25:32 +00:00
33 lines
833 B
Rust
33 lines
833 B
Rust
pub mod error;
|
|
pub use error::Error;
|
|
|
|
use glib::GString;
|
|
|
|
/// Entire meta buffer, but [status code](https://geminiprotocol.net/docs/protocol-specification.gmi#status-codes).
|
|
///
|
|
/// Usefult to grab placeholder text on 10, 11, 31 codes processing
|
|
pub struct Meta {
|
|
buffer: Vec<u8>,
|
|
}
|
|
|
|
impl Meta {
|
|
pub fn from_header(buffer: &[u8]) -> Result<Self, Error> {
|
|
match buffer.get(3..) {
|
|
Some(value) => Ok(Self {
|
|
buffer: value.to_vec(),
|
|
}),
|
|
None => return Err(Error::Undefined),
|
|
}
|
|
}
|
|
|
|
pub fn to_gstring(&self) -> Result<GString, Error> {
|
|
match GString::from_utf8(self.buffer.clone()) {
|
|
Ok(result) => Ok(result),
|
|
Err(_) => Err(Error::Undefined),
|
|
}
|
|
}
|
|
|
|
pub fn buffer(&self) -> &[u8] {
|
|
&self.buffer
|
|
}
|
|
}
|