🏗️ Elegant & Highly Performant Async Gemini Server Framework for the Modern Age
async framework gemini-protocol protocol gemini rust
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(windmark): prelude feature flag

Fuwn d66da17c 58e0b15e

+88 -56
+1
Cargo.toml
··· 24 24 response-macros = [] 25 25 tokio = ["dep:tokio", "tokio-openssl"] 26 26 async-std = ["dep:async-std", "async-std-openssl"] 27 + prelude = [] 27 28 28 29 [dependencies] 29 30 # SSL
+2 -2
examples/async.rs
··· 19 19 20 20 #[windmark::main] 21 21 async fn main() -> Result<(), Box<dyn std::error::Error>> { 22 - let mut router = windmark::Router::new(); 22 + let mut router = windmark::router::Router::new(); 23 23 #[cfg(feature = "tokio")] 24 24 let async_clicks = std::sync::Arc::new(tokio::sync::Mutex::new(0)); 25 25 #[cfg(feature = "async-std")] ··· 35 35 36 36 *clicks += 1; 37 37 38 - windmark::Response::success(*clicks) 38 + windmark::response::Response::success(*clicks) 39 39 } 40 40 }); 41 41 router.mount(
+2 -2
examples/async_stateful_module.rs
··· 17 17 18 18 //! `cargo run --example async_stateful_module --features response-macros` 19 19 20 - use windmark::{context::HookContext, Router}; 20 + use windmark::{context::HookContext, router::Router}; 21 21 22 22 #[derive(Default)] 23 23 struct Clicker { ··· 25 25 } 26 26 27 27 #[async_trait::async_trait] 28 - impl windmark::AsyncModule for Clicker { 28 + impl windmark::module::AsyncModule for Clicker { 29 29 async fn on_attach(&mut self, _router: &mut Router) { 30 30 println!("module 'clicker' has been attached!"); 31 31 }
+1 -1
examples/binary.rs
··· 22 22 23 23 #[windmark::main] 24 24 async fn main() -> Result<(), Box<dyn std::error::Error>> { 25 - let mut router = windmark::Router::new(); 25 + let mut router = windmark::router::Router::new(); 26 26 27 27 router.set_private_key_file("windmark_private.pem"); 28 28 router.set_certificate_file("windmark_public.pem");
+2 -2
examples/callbacks.rs
··· 21 21 22 22 #[windmark::main] 23 23 async fn main() -> Result<(), Box<dyn std::error::Error>> { 24 - windmark::Router::new() 24 + windmark::router::Router::new() 25 25 .set_private_key_file("windmark_private.pem") 26 26 .set_certificate_file("windmark_public.pem") 27 27 .mount("/", windmark::success!("Hello!")) ··· 33 33 ) 34 34 }) 35 35 .set_post_route_callback( 36 - |context: HookContext, content: &mut windmark::Response| { 36 + |context: HookContext, content: &mut windmark::response::Response| { 37 37 content.content = content.content.replace("Hello", "Hi"); 38 38 39 39 println!(
+2 -2
examples/certificate.rs
··· 17 17 18 18 //! `cargo run --example certificate --features response-macros` 19 19 20 - use windmark::Response; 20 + use windmark::response::Response; 21 21 22 22 #[windmark::main] 23 23 async fn main() -> Result<(), Box<dyn std::error::Error>> { 24 - windmark::Router::new() 24 + windmark::router::Router::new() 25 25 .set_private_key_file("windmark_private.pem") 26 26 .set_certificate_file("windmark_public.pem") 27 27 .mount("/secret", |context: windmark::context::RouteContext| {
+1 -1
examples/default_logger.rs
··· 19 19 20 20 #[windmark::main] 21 21 async fn main() -> Result<(), Box<dyn std::error::Error>> { 22 - let mut router = windmark::Router::new(); 22 + let mut router = windmark::router::Router::new(); 23 23 24 24 router.set_private_key_file("windmark_private.pem"); 25 25 router.set_certificate_file("windmark_public.pem");
+1 -1
examples/empty.rs
··· 19 19 20 20 #[windmark::main] 21 21 async fn main() -> Result<(), Box<dyn std::error::Error>> { 22 - windmark::Router::new() 22 + windmark::router::Router::new() 23 23 .set_private_key_file("windmark_private.pem") 24 24 .set_certificate_file("windmark_public.pem") 25 25 .run()
+2 -2
examples/error_handler.rs
··· 17 17 18 18 //! `cargo run --example error_handler` 19 19 20 - use windmark::Response; 20 + use windmark::response::Response; 21 21 22 22 #[windmark::main] 23 23 async fn main() -> Result<(), Box<dyn std::error::Error>> { 24 24 let mut error_count = 0; 25 25 26 - windmark::Router::new() 26 + windmark::router::Router::new() 27 27 .set_private_key_file("windmark_private.pem") 28 28 .set_certificate_file("windmark_public.pem") 29 29 .set_error_handler(move |_| {
+1 -1
examples/fix_path.rs
··· 19 19 20 20 #[windmark::main] 21 21 async fn main() -> Result<(), Box<dyn std::error::Error>> { 22 - windmark::Router::new() 22 + windmark::router::Router::new() 23 23 .set_private_key_file("windmark_private.pem") 24 24 .set_certificate_file("windmark_public.pem") 25 25 .set_fix_path(true)
+2 -2
examples/input.rs
··· 17 17 18 18 //! `cargo run --example input` 19 19 20 - use windmark::{context::RouteContext, Response}; 20 + use windmark::{context::RouteContext, response::Response}; 21 21 22 22 #[windmark::main] 23 23 async fn main() -> Result<(), Box<dyn std::error::Error>> { 24 - windmark::Router::new() 24 + windmark::router::Router::new() 25 25 .set_private_key_file("windmark_private.pem") 26 26 .set_certificate_file("windmark_public.pem") 27 27 .mount("/input", |context: RouteContext| {
+2 -2
examples/mime.rs
··· 19 19 20 20 #[windmark::main] 21 21 async fn main() -> Result<(), Box<dyn std::error::Error>> { 22 - windmark::Router::new() 22 + windmark::router::Router::new() 23 23 .set_private_key_file("windmark_private.pem") 24 24 .set_certificate_file("windmark_public.pem") 25 25 .mount("/mime", |_| { 26 - windmark::Response::success("Hello!".to_string()) 26 + windmark::response::Response::success("Hello!".to_string()) 27 27 .with_mime("text/plain") 28 28 .clone() 29 29 })
+1 -1
examples/parameters.rs
··· 21 21 22 22 #[windmark::main] 23 23 async fn main() -> Result<(), Box<dyn std::error::Error>> { 24 - windmark::Router::new() 24 + windmark::router::Router::new() 25 25 .set_private_key_file("windmark_private.pem") 26 26 .set_certificate_file("windmark_public.pem") 27 27 .mount(
+1 -1
examples/partial.rs
··· 19 19 20 20 #[windmark::main] 21 21 async fn main() -> Result<(), Box<dyn std::error::Error>> { 22 - windmark::Router::new() 22 + windmark::router::Router::new() 23 23 .set_private_key_file("windmark_private.pem") 24 24 .set_certificate_file("windmark_public.pem") 25 25 .add_header(|_| "This is fancy art.\n".to_string())
+1 -1
examples/query.rs
··· 19 19 20 20 #[windmark::main] 21 21 async fn main() -> Result<(), Box<dyn std::error::Error>> { 22 - windmark::Router::new() 22 + windmark::router::Router::new() 23 23 .set_private_key_file("windmark_private.pem") 24 24 .set_certificate_file("windmark_public.pem") 25 25 .mount(
+1 -1
examples/responses.rs
··· 21 21 22 22 #[windmark::main] 23 23 async fn main() -> Result<(), Box<dyn std::error::Error>> { 24 - windmark::Router::new() 24 + windmark::router::Router::new() 25 25 .set_private_key_file("windmark_private.pem") 26 26 .set_certificate_file("windmark_public.pem") 27 27 .mount(
+4 -2
examples/simple_async_std.rs
··· 19 19 20 20 #[windmark::main] 21 21 async fn main() -> Result<(), Box<dyn std::error::Error>> { 22 - windmark::Router::new() 22 + windmark::router::Router::new() 23 23 .set_private_key_file("windmark_private.pem") 24 24 .set_certificate_file("windmark_public.pem") 25 - .mount("/", |_| windmark::Response::success("Hello, async-std!")) 25 + .mount("/", |_| { 26 + windmark::response::Response::success("Hello, async-std!") 27 + }) 26 28 .run() 27 29 .await 28 30 }
+4 -2
examples/simple_tokio.rs
··· 19 19 20 20 #[windmark::main] 21 21 async fn main() -> Result<(), Box<dyn std::error::Error>> { 22 - windmark::Router::new() 22 + windmark::router::Router::new() 23 23 .set_private_key_file("windmark_private.pem") 24 24 .set_certificate_file("windmark_public.pem") 25 - .mount("/", |_| windmark::Response::success("Hello, Tokio!")) 25 + .mount("/", |_| { 26 + windmark::response::Response::success("Hello, Tokio!") 27 + }) 26 28 .run() 27 29 .await 28 30 }
+2 -2
examples/stateful_module.rs
··· 17 17 18 18 //! `cargo run --example stateful_module --features response-macros` 19 19 20 - use windmark::{context::HookContext, Router}; 20 + use windmark::{context::HookContext, router::Router}; 21 21 22 22 #[derive(Default)] 23 23 struct Clicker { 24 24 clicks: usize, 25 25 } 26 26 27 - impl windmark::Module for Clicker { 27 + impl windmark::module::Module for Clicker { 28 28 fn on_attach(&mut self, _router: &mut Router) { 29 29 println!("module 'clicker' has been attached!"); 30 30 }
+3 -3
examples/stateless_module.rs
··· 17 17 18 18 //! `cargo run --example stateless_module` 19 19 20 - use windmark::Router; 20 + use windmark::{response::Response, router::Router}; 21 21 22 - fn smiley(_context: windmark::context::RouteContext) -> windmark::Response { 23 - windmark::Response::success("😀") 22 + fn smiley(_context: windmark::context::RouteContext) -> Response { 23 + Response::success("😀") 24 24 } 25 25 26 26 fn emojis(router: &mut Router) { router.mount("/smiley", smiley); }
+3 -4
examples/struct_router.rs
··· 18 18 //! `cargo run --example struct_router` 19 19 20 20 use rossweisse::route; 21 + use windmark::response::Response; 21 22 22 23 #[rossweisse::router] 23 24 struct Router { ··· 27 28 #[rossweisse::router] 28 29 impl Router { 29 30 #[route(index)] 30 - pub fn index( 31 - _context: windmark::context::RouteContext, 32 - ) -> windmark::Response { 33 - windmark::Response::success("Hello, World!") 31 + pub fn index(_context: windmark::context::RouteContext) -> Response { 32 + Response::success("Hello, World!") 34 33 } 35 34 } 36 35
+3 -3
rossweisse/src/implementations/router/fields.rs
··· 58 58 fn _new() -> Self { 59 59 Self { 60 60 #(#new_method_fields)* 61 - router: ::windmark::Router::new(), 61 + router: ::windmark::router::Router::new(), 62 62 } 63 63 } 64 64 ··· 66 66 self.router.run().await 67 67 } 68 68 69 - pub fn router(&mut self) -> &mut ::windmark::Router { 69 + pub fn router(&mut self) -> &mut ::windmark::router::Router { 70 70 &mut self.router 71 71 } 72 72 }; ··· 74 74 let output = quote! { 75 75 struct #router_identifier { 76 76 #output_fields 77 - router: ::windmark::Router, 77 + router: ::windmark::router::Router, 78 78 } 79 79 80 80 impl #router_identifier {
+1 -1
src/handler/hooks/post_route.rs
··· 15 15 // Copyright (C) 2022-2023 Fuwn <contact@fuwn.me> 16 16 // SPDX-License-Identifier: GPL-3.0-only 17 17 18 - use crate::{context::HookContext, Response}; 18 + use crate::{context::HookContext, response::Response}; 19 19 20 20 #[allow(clippy::module_name_repetitions)] 21 21 pub trait PostRouteHook: Send + Sync {
+1 -1
src/handler/response/error.rs
··· 17 17 18 18 use async_trait::async_trait; 19 19 20 - use crate::{context::ErrorContext, Response}; 20 + use crate::{context::ErrorContext, response::Response}; 21 21 22 22 #[allow(clippy::module_name_repetitions)] 23 23 #[async_trait]
+1 -1
src/handler/response/route.rs
··· 17 17 18 18 use async_trait::async_trait; 19 19 20 - use crate::{context::RouteContext, Response}; 20 + use crate::{context::RouteContext, response::Response}; 21 21 22 22 #[allow(clippy::module_name_repetitions)] 23 23 #[async_trait]
+2 -3
src/lib.rs
··· 32 32 pub mod context; 33 33 pub mod handler; 34 34 pub mod module; 35 + #[cfg(feature = "prelude")] 36 + pub mod prelude; 35 37 pub mod response; 36 38 pub mod router; 37 39 pub mod utilities; ··· 41 43 42 44 #[cfg(feature = "async-std")] 43 45 pub use async_std::main; 44 - pub use module::{AsyncModule, Module}; 45 - pub use response::Response; 46 - pub use router::Router; 47 46 #[cfg(feature = "tokio")] 48 47 pub use tokio::main;
+1 -1
src/module/asynchronous.rs
··· 20 20 #[async_trait::async_trait] 21 21 pub trait AsyncModule: Send + Sync { 22 22 /// Called right after the module is attached. 23 - async fn on_attach(&mut self, _: &mut crate::Router) {} 23 + async fn on_attach(&mut self, _: &mut crate::router::Router) {} 24 24 25 25 /// Called before a route is mounted. 26 26 async fn on_pre_route(&mut self, _: HookContext) {}
+1 -1
src/module/sync.rs
··· 19 19 20 20 pub trait Module { 21 21 /// Called right after the module is attached. 22 - fn on_attach(&mut self, _: &mut crate::Router) {} 22 + fn on_attach(&mut self, _: &mut crate::router::Router) {} 23 23 24 24 /// Called before a route is mounted. 25 25 fn on_pre_route(&mut self, _: HookContext) {}
+23
src/prelude.rs
··· 1 + // This file is part of Windmark <https://github.com/gemrest/windmark>. 2 + // 3 + // This program is free software: you can redistribute it and/or modify 4 + // it under the terms of the GNU General Public License as published by 5 + // the Free Software Foundation, version 3. 6 + // 7 + // This program is distributed in the hope that it will be useful, but 8 + // WITHOUT ANY WARRANTY; without even the implied warranty of 9 + // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 + // General Public License for more details. 11 + // 12 + // You should have received a copy of the GNU General Public License 13 + // along with this program. If not, see <http://www.gnu.org/licenses/>. 14 + // 15 + // Copyright (C) 2022-2023 Fuwn <contact@fuwn.me> 16 + // SPDX-License-Identifier: GPL-3.0-only 17 + 18 + pub use crate::{ 19 + context, 20 + module::{AsyncModule, Module}, 21 + response::Response, 22 + router::Router, 23 + };
+16 -10
src/response/macros.rs
··· 22 22 #[macro_export] 23 23 macro_rules! $name { 24 24 ($body:expr /* $(,)? */) => { 25 - |_: $crate::context::RouteContext| $crate::Response::$name($body) 25 + |_: $crate::context::RouteContext| $crate::response::Response::$name($body) 26 26 }; 27 27 ($context:ident, $body:expr /* $(,)? */) => { 28 - |$context: $crate::context::RouteContext| $crate::Response::$name($body) 28 + |$context: $crate::context::RouteContext| $crate::response::Response::$name($body) 29 29 }; 30 30 } 31 31 )* ··· 39 39 #[macro_export] 40 40 macro_rules! [< $name _async >] { 41 41 ($body:expr /* $(,)? */) => { 42 - |_: $crate::context::RouteContext| async { $crate::Response::$name($body) } 42 + |_: $crate::context::RouteContext| async { $crate::response::Response::$name($body) } 43 43 }; 44 44 ($context:ident, $body:expr /* $(,)? */) => { 45 - |$context: $crate::context::RouteContext| async { $crate::Response::$name($body) } 45 + |$context: $crate::context::RouteContext| async { $crate::response::Response::$name($body) } 46 46 }; 47 47 } 48 48 })* ··· 86 86 macro_rules! binary_success { 87 87 ($body:expr, $mime:expr) => { 88 88 |_: $crate::context::RouteContext| { 89 - $crate::Response::binary_success($body, $mime) 89 + $crate::response::Response::binary_success($body, $mime) 90 90 } 91 91 }; 92 92 ($body:expr) => {{ ··· 98 98 99 99 |_: $crate::context::RouteContext| { 100 100 #[cfg(feature = "auto-deduce-mime")] 101 - return $crate::Response::binary_success_auto($body); 101 + return $crate::response::Response::binary_success_auto($body); 102 102 103 103 // Suppress item not found warning 104 104 #[cfg(not(feature = "auto-deduce-mime"))] 105 - $crate::Response::binary_success($body, "application/octet-stream") 105 + $crate::response::Response::binary_success( 106 + $body, 107 + "application/octet-stream", 108 + ) 106 109 } 107 110 }}; 108 111 ($context:ident, $body:expr, $mime:expr) => { 109 112 |$context: $crate::context::RouteContext| { 110 - $crate::Response::binary_success($body, $mime) 113 + $crate::response::Response::binary_success($body, $mime) 111 114 } 112 115 }; 113 116 ($context:ident, $body:expr) => {{ ··· 119 122 120 123 |$context: $crate::context::RouteContext| { 121 124 #[cfg(feature = "auto-deduce-mime")] 122 - return $crate::Response::binary_success_auto($body); 125 + return $crate::response::Response::binary_success_auto($body); 123 126 124 127 // Suppress item not found warning 125 128 #[cfg(not(feature = "auto-deduce-mime"))] 126 - $crate::Response::binary_success($body, "application/octet-stream") 129 + $crate::response::Response::binary_success( 130 + $body, 131 + "application/octet-stream", 132 + ) 127 133 } 128 134 }}; 129 135 }