🏗️ 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.

refactor(partial): into trait

Fuwn 9934455d c7cdfab1

+17 -8
+1 -1
examples/windmark.rs
··· 98 98 }); 99 99 router.add_header(|_| "```\nART IS COOL\n```\nhi".to_string()); 100 100 router.add_footer(|_| "Copyright 2022".to_string()); 101 - router.add_footer(|context| { 101 + router.add_footer(|context: RouteContext| { 102 102 format!("Another footer, but lower! (from {})", context.url.path()) 103 103 }); 104 104 router.mount(
+9 -2
src/handler/partial.rs
··· 18 18 19 19 use crate::context::RouteContext; 20 20 21 - pub trait Partial: FnMut(RouteContext) -> String + Send + Sync {} 21 + #[allow(clippy::module_name_repetitions)] 22 + pub trait Partial: Send + Sync { 23 + fn call(&mut self, context: RouteContext) -> String; 24 + } 22 25 23 - impl<T> Partial for T where T: FnMut(RouteContext) -> String + Send + Sync {} 26 + impl<T> Partial for T 27 + where T: FnMut(RouteContext) -> String + Send + Sync 28 + { 29 + fn call(&mut self, context: RouteContext) -> String { (*self)(context) } 30 + }
+7 -5
src/router.rs
··· 78 78 error_handler: Arc<AsyncMutex<Box<dyn ErrorResponse>>>, 79 79 private_key_file_name: String, 80 80 ca_file_name: String, 81 - headers: Arc<Mutex<Vec<Box<dyn Partial<Output = String>>>>>, 82 - footers: Arc<Mutex<Vec<Box<dyn Partial<Output = String>>>>>, 81 + headers: Arc<Mutex<Vec<Box<dyn Partial>>>>, 82 + footers: Arc<Mutex<Vec<Box<dyn Partial>>>>, 83 83 ssl_acceptor: Arc<SslAcceptor>, 84 84 #[cfg(feature = "logger")] 85 85 default_logger: bool, ··· 380 380 ); 381 381 382 382 for partial_header in &mut *self.headers.lock().unwrap() { 383 - header 384 - .push_str(&format!("{}\n", partial_header(route_context.clone()),)); 383 + header.push_str(&format!( 384 + "{}\n", 385 + partial_header.call(route_context.clone()), 386 + )); 385 387 } 386 388 387 389 for (i, partial_footer) in { ··· 390 392 } { 391 393 footer.push_str(&format!( 392 394 "{}{}", 393 - partial_footer(route_context.clone()), 395 + partial_footer.call(route_context.clone()), 394 396 if footers_length > 1 && i != footers_length - 1 { 395 397 "\n" 396 398 } else {