diff options
| author | Fuwn <[email protected]> | 2022-03-27 07:00:44 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2022-03-27 07:00:44 +0000 |
| commit | 18d4ac1f2e9782654494c957927c2a5cc6a2915c (patch) | |
| tree | d5c13fa5595d2efe1cd9a724ddf13a116bc91d0c /src | |
| parent | docs(readme): fix example (diff) | |
| download | windmark-0.1.2.tar.xz windmark-0.1.2.zip | |
docs: extend0.1.2
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib.rs | 55 | ||||
| -rw-r--r-- | src/response.rs | 3 | ||||
| -rw-r--r-- | src/utilities.rs | 3 |
3 files changed, 61 insertions, 0 deletions
@@ -16,6 +16,59 @@ // Copyright (C) 2022-2022 Fuwn <[email protected]> // SPDX-License-Identifier: GPL-3.0-only +//! # Windmark +//! +//! [](https://crates.io/crates/windmark) +//! [](https://docs.rs/windmark) +//! [](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<dyn std::error::Error>> { +//! 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<RouteResponse>, 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 <[email protected]> // 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 <[email protected]> // 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<String, String> { let mut queries = HashMap::new(); |