add documentation comments

This commit is contained in:
yggverse 2024-11-01 19:12:19 +02:00
parent 9dd1bcc9dd
commit c4fa868345

View file

@ -1,37 +1,34 @@
//! Parser and holder API for [Status code](https://geminiprotocol.net/docs/protocol-specification.gmi#status-codes) //! Parser and holder tools for
//! [Status code](https://geminiprotocol.net/docs/protocol-specification.gmi#status-codes)
pub mod error; pub mod error;
pub use error::Error; pub use error::Error;
use glib::GString; use glib::GString;
/// Holder for [status code](https://geminiprotocol.net/docs/protocol-specification.gmi#status-codes)
#[derive(Debug)] #[derive(Debug)]
pub enum Status { pub enum Status {
// Input // Input
Input = 10, Input = 10,
SensitiveInput = 11, SensitiveInput = 11,
// Success // Success
Success = 20, Success = 20,
// Redirect // Redirect
Redirect = 30, Redirect = 30,
PermanentRedirect = 31, PermanentRedirect = 31,
// Temporary failure // Temporary failure
TemporaryFailure = 40, TemporaryFailure = 40,
ServerUnavailable = 41, ServerUnavailable = 41,
CgiError = 42, CgiError = 42,
ProxyError = 43, ProxyError = 43,
SlowDown = 44, SlowDown = 44,
// Permanent failure // Permanent failure
PermanentFailure = 50, PermanentFailure = 50,
NotFound = 51, NotFound = 51,
ResourceGone = 52, ResourceGone = 52,
ProxyRequestRefused = 53, ProxyRequestRefused = 53,
BadRequest = 59, BadRequest = 59,
// Client certificates // Client certificates
CertificateRequest = 60, CertificateRequest = 60,
CertificateUnauthorized = 61, CertificateUnauthorized = 61,
@ -39,6 +36,9 @@ pub enum Status {
} }
impl Status { impl Status {
/// Create new `Self` from UTF-8 buffer
///
/// * includes `Self::from_string` parser, it means that given buffer should contain some **header**
pub fn from_utf8(buffer: &[u8]) -> Result<Self, Error> { pub fn from_utf8(buffer: &[u8]) -> Result<Self, Error> {
match buffer.get(0..2) { match buffer.get(0..2) {
Some(value) => match GString::from_utf8(value.to_vec()) { Some(value) => match GString::from_utf8(value.to_vec()) {
@ -49,6 +49,7 @@ impl Status {
} }
} }
/// Create new `Self` from string that includes **header**
pub fn from_string(code: &str) -> Result<Self, Error> { pub fn from_string(code: &str) -> Result<Self, Error> {
match code { match code {
// Input // Input