From f3279b6188c18291f6b2333aa30429f0402a4a98 Mon Sep 17 00:00:00 2001 From: Celeste Date: Sat, 12 Mar 2022 21:05:43 +0000 Subject: [PATCH] I thoroughly apologise to the people who want to use this crate seeing the nightmare of updates torrenting out today but the lack of documentation on the gemini module makes me extremely angry and you like documentation too so here you go. --- Cargo.toml | 2 +- src/gemini.rs | 36 ++++++++++++++++++------------------ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 702d014..46e0b3e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "packeteer" description = "An attempt at a Rust library that can be used to assist in programmatically analysing, serving and handling received protocol packets." -version = "0.2.1" +version = "0.2.2" edition = "2021" authors = ["Celeste "] license = "LGPL-3.0-or-later" diff --git a/src/gemini.rs b/src/gemini.rs index e073b7e..9e85fb3 100644 --- a/src/gemini.rs +++ b/src/gemini.rs @@ -3,15 +3,15 @@ use super::{Url, wrap_url, unwrap_url}; use std::str::FromStr; -// A structure for Gemini requests. -// Generated with packeteer::gemini::generate_request +/// A structure for Gemini requests. +/// Generated with packeteer::gemini::generate_request #[derive(Debug)] pub struct GeminiRequest { pub url: Url, } -// A structure for Gemini responses. -// Generated with packeteer::gemini::generate_response +/// A structure for Gemini responses. +/// Generated with packeteer::gemini::generate_response #[derive(Debug)] pub struct GeminiResponse { pub code: i32, @@ -19,15 +19,15 @@ pub struct GeminiResponse { pub body: String, } -// A function for generating GeminiRequest structures. +/// A function for generating GeminiRequest structures. pub fn generate_request(url: &str) -> GeminiRequest { let wurl = wrap_url(url); let gem = GeminiRequest { url: wurl }; return gem } -// A function for generating GeminiResponse structures. -// Any invalid status code (valid status codes are 69 > x >= 10) will automatically be switched to 40 (Temporary failure). +/// A function for generating GeminiResponse structures. +/// Any invalid status code (valid status codes are 69 > x >= 10) will automatically be switched to 40 (Temporary failure). pub fn generate_response(code: i32, body: &str) -> GeminiResponse { let mut xcode = code; if code < 10 { xcode = 40 }; @@ -36,26 +36,26 @@ pub fn generate_response(code: i32, body: &str) -> GeminiResponse { return res } -// A function for converting GeminiRequest structures into a Gemini request string. -// This is extremely simple since GeminiRequest is basically storing a Url. -// Unpacking functions are simply taking the data stored in the structure and concatenating it into a string so nothing changes apart from the conversion. +/// A function for converting GeminiRequest structures into a Gemini request string. +/// This is extremely simple since GeminiRequest is basically storing a Url. +/// Unpacking functions are simply taking the data stored in the structure and concatenating it into a string so nothing changes apart from the conversion. pub fn unpack_request(req: GeminiRequest) -> String { let url = unwrap_url(req.url); let string = format!("{}\r\n", url); return string.to_string() } -// A function for converting GeminiResponse structures into split header and body strings. -// The header and body are split as the Gemini specification seperates them. -// Unpacking functions are simply taking the data stored in the structure and concatenating it into a string so nothing changes apart from the conversion. +/// A function for converting GeminiResponse structures into split header and body strings. +/// The header and body are split as the Gemini specification seperates them. +/// Unpacking functions are simply taking the data stored in the structure and concatenating it into a string so nothing changes apart from the conversion. pub fn unpack_response(res: GeminiResponse) -> (String, String) { let string = format!("{} {}\r\n", res.code, res.meta); return (string.to_string(), res.body) } -// A function for converting Gemini request strings into GeminiRequest. -// This is essentially equivalent to packeteer::gemini::generate_request apart from the fact it automatically removes the character return and line feed after the URL to allow for conversion from raw Gemini requests. -// Construction functions aim to be as transparent as possible so apart from turning it into a structure, the request stays relatively unchanged. +/// A function for converting Gemini request strings into GeminiRequest. +/// This is essentially equivalent to packeteer::gemini::generate_request apart from the fact it automatically removes the character return and line feed after the URL to allow for conversion from raw Gemini requests. +/// Construction functions aim to be as transparent as possible so apart from turning it into a structure, the request stays relatively unchanged. pub fn construct_request(req: &str) -> GeminiRequest { let url: Vec<&str> = req.split("\r\n").collect(); let wurl = wrap_url(url[0]); @@ -63,8 +63,8 @@ pub fn construct_request(req: &str) -> GeminiRequest { return gem } -// A function for converting Gemini header and body strings into GeminiResponse. -// Construction functions aim to be as transparent as possible so apart from turning it into a structure, the response stays relatively unchanged. +/// A function for converting Gemini header and body strings into GeminiResponse. +/// Construction functions aim to be as transparent as possible so apart from turning it into a structure, the response stays relatively unchanged. pub fn construct_response(res: &str, body: &str) -> GeminiResponse { let split1: Vec<&str> = res.split("\r\n").collect(); let split2: Vec<&str> = split1[0].split(" ").collect();