Skip to content
Snippets Groups Projects
Commit 47cf59bd authored by codecraft's avatar codecraft :crocodile:
Browse files

Add some documentation

parent 02b28058
No related branches found
No related tags found
1 merge request!1Initial feature merge
use crate::{handling::routes::Body, utils::mime::Mime};
pub trait ResponseBody: Send {
/// Get a cloned version of the data as a [Vec<u8>]
/// Get a cloned version of the data as a [`Vec<u8>`]
/// # Ecamples
/// ```
/// use http::handling::response::ResponseBody;
......
......@@ -16,13 +16,34 @@ pub struct RoutInfo {
rank: Option<isize>,
}
/// A struct to define Routes on the Server
#[derive(Clone, Copy)]
pub struct Route<'a> {
/// An optional name of the route
pub name: Option<&'static str>,
/// The [Method] via which the route is accesable
pub method: Method,
/// The Uri of the route, allows special cases:
/// # Examples
/// ```
/// "/home"; // Only /home
/// "/<home>/something";
/// // Variable content the users provides this acts for /<anything>/something
/// "/<home..>";
/// // All Information after this sequence is irrelvent
/// // Matches: /a, /a/b/c ...
/// ```
pub uri: Uri<'a>,
/// The Handler function for this route, which gets called when the request need the route.
/// Inputs to the function are an [Request] and the [Data] which represents the body of the
/// [Request]. The Outcome is expected to be an [Outcome], which is a [Response], A [Status] if
/// something went wrong and a [Status] page is need or a [Outcome::Forward] of the requests
/// [Data] for the next [Route] to take care of.
pub handler: fn(Request, Data) -> Outcome<Response, Status, Data>,
/// The Rank of the Route, dependent on its specificness. so the rank of a uri `"/home"` would be
/// ranked high, whereas a uri of `"/<anything..>"` would be ranked the lowest
pub rank: isize,
/// The Specific answer format of the [Route] as a [MediaType]. Optional
pub format: Option<MediaType>,
}
......@@ -38,6 +59,7 @@ impl Route<'_> {
format: routeinfo.format,
}
}
/// Matches a [Request] Uri with a [Route] Uri. Respecting special cases like `?` and `<a..>`
pub fn compare_uri(&self, uri: Uri) -> bool {
let mut iter_comp_str = uri.split('/');
for true_str in self.uri.split('/') {
......@@ -65,8 +87,11 @@ impl Route<'_> {
pub type Uri<'a> = &'a str;
#[derive(Debug, Clone)]
/// A basic Body type for respones
pub struct Body {
/// The Response body
body: Vec<u8>,
/// The Mime Type
mime_type: Mime,
}
......@@ -89,8 +114,11 @@ impl Body {
}
#[derive(Debug, Clone)]
/// Data of the Body of a [Request]
pub struct Data {
/// The Data
pub buffer: Vec<u8>,
/// For Split Data if it is complete
pub is_complete: bool,
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment