mirror of
https://github.com/YGGverse/ggemini.git
synced 2026-04-01 09:35:33 +00:00
draft new api version
This commit is contained in:
parent
8a5f1e2a57
commit
3cde80b6a8
22 changed files with 323 additions and 747 deletions
|
|
@ -1,7 +1,7 @@
|
|||
pub mod error;
|
||||
pub use error::Error;
|
||||
|
||||
use glib::GString;
|
||||
use glib::{Bytes, GString};
|
||||
|
||||
/// https://geminiprotocol.net/docs/protocol-specification.gmi#status-codes
|
||||
pub enum Status {
|
||||
|
|
@ -11,21 +11,23 @@ pub enum Status {
|
|||
Redirect,
|
||||
} // @TODO
|
||||
|
||||
pub fn from_header(buffer: &[u8] /* @TODO */) -> Result<Status, Error> {
|
||||
match buffer.get(0..2) {
|
||||
Some(bytes) => match GString::from_utf8(bytes.to_vec()) {
|
||||
Ok(string) => from_string(string.as_str()),
|
||||
Err(_) => Err(Error::Decode),
|
||||
},
|
||||
None => Err(Error::Undefined),
|
||||
impl Status {
|
||||
pub fn from_header(bytes: &Bytes) -> Result<Self, Error> {
|
||||
match bytes.get(0..2) {
|
||||
Some(bytes) => match GString::from_utf8(bytes.to_vec()) {
|
||||
Ok(string) => Self::from_string(string.as_str()),
|
||||
Err(_) => Err(Error::Decode),
|
||||
},
|
||||
None => Err(Error::Undefined),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_string(code: &str) -> Result<Status, Error> {
|
||||
match code {
|
||||
"10" => Ok(Status::Input),
|
||||
"11" => Ok(Status::SensitiveInput),
|
||||
"20" => Ok(Status::Success),
|
||||
_ => Err(Error::Undefined),
|
||||
pub fn from_string(code: &str) -> Result<Self, Error> {
|
||||
match code {
|
||||
"10" => Ok(Self::Input),
|
||||
"11" => Ok(Self::SensitiveInput),
|
||||
"20" => Ok(Self::Success),
|
||||
_ => Err(Error::Undefined),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue