From b9d9031dc938900a96ae0e27df16931b21083a1f Mon Sep 17 00:00:00 2001 From: Fuwn Date: Sun, 27 Mar 2022 07:00:44 +0000 Subject: docs: extend --- src/lib.rs | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/response.rs | 3 +++ src/utilities.rs | 3 +++ 3 files changed, 61 insertions(+) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index 1563c62..0c6ebf7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,6 +16,59 @@ // Copyright (C) 2022-2022 Fuwn // SPDX-License-Identifier: GPL-3.0-only +//! # Windmark +//! +//! [![crates.io](https://img.shields.io/crates/v/windmark.svg)](https://crates.io/crates/windmark) +//! [![docs.rs](https://docs.rs/windmark/badge.svg)](https://docs.rs/windmark) +//! [![github.com](https://github.com/gemrest/windmark/actions/workflows/check.yaml/badge.svg?branch=main)](https://github.com/gemrest/windmark/actions/workflows/check.yaml) +//! +//! Windmark is an elegant and highly performant, async Gemini server framework. +//! +//! ## Usage +//! +//! ### Add Windmark as a dependency +//! +//! ```toml +//! # Cargo.toml +//! +//! [dependencies] +//! windmark = "0.1.2" +//! +//! # If you would like to use the built-in logger (recommended) +//! # windmark = { version = "0.1.2", features = ["logger"] } +//! ``` +//! +//! ### Implement a Windmark server +//! +//! ```rust +//! // src/main.rs +//! +//! use windmark::Response; +//! +//! #[windmark::main] +//! fn main() -> Result<(), Box> { +//! windmark::Router::new() +//! .set_private_key_file("windmark_private.pem") +//! .set_certificate_chain_file("windmark_pair.pem") +//! .mount("/", |_| Response::Success("Hello, World!".into())) +//! .set_error_handler(|_| { +//! Response::PermanentFailure("This route does not exist!".into()) +//! }) +//! .run() +//! .await +//! } +//! ``` +//! +//! ## Examples +//! +//! Examples can be found within the +//! [`examples/`](https://github.com/gemrest/windmark/tree/main/examples) directory. +//! +//! ## License +//! +//! This project is licensed with the +//! [GNU General Public License v3.0](https://github.com/gemrest/windmark/blob/main/LICENSE). + #![feature(once_cell)] #![deny( warnings, @@ -53,6 +106,8 @@ use crate::{ returnable::{ErrorContext, RouteContext}, }; +/// A router which takes care of all tasks a Windmark server should handle: +/// response generation, panics, logging, and more. #[derive(Clone)] pub struct Router { routes: matchit::Router, diff --git a/src/response.rs b/src/response.rs index d89dbf2..b9c5354 100644 --- a/src/response.rs +++ b/src/response.rs @@ -16,6 +16,9 @@ // Copyright (C) 2022-2022 Fuwn // SPDX-License-Identifier: GPL-3.0-only +//! Content and response handlers + +/// The content and response type a handler should reply with. pub enum Response<'a> { Input(String), SensitiveInput(String), diff --git a/src/utilities.rs b/src/utilities.rs index 0d34dba..68962ff 100644 --- a/src/utilities.rs +++ b/src/utilities.rs @@ -16,8 +16,11 @@ // Copyright (C) 2022-2022 Fuwn // SPDX-License-Identifier: GPL-3.0-only +//! Utilities to make cumbersome tasks simpler + use std::collections::HashMap; +/// Extract the queries from a URL into a `HashMap`. #[must_use] pub fn queries_from_url(url: &url::Url) -> HashMap { let mut queries = HashMap::new(); -- cgit v1.2.3