hyper_static_server/
runtime.rs

1
2
3use crate::hss;
4
5
6use ::std::{
7		
8		fmt,
9		
10		ops::Deref as _,
11		
12	};
13
14
15use crate::{
16		
17		hss::ServerResult,
18		hss::Extensions,
19		hss::ContentType,
20		hss::HandlerDynArc,
21		
22	};
23
24
25
26
27pub trait StaticResource
28		where Self : Sized
29{
30	fn content_type (&self) -> ContentType;
31	fn description (&self) -> &'static str;
32	fn into_handler_dyn (self) -> HandlerDynArc;
33}
34
35
36pub trait StaticRoute
37		where Self : Sized
38{
39	fn into_route (self) -> hss::Route;
40}
41
42
43pub trait StaticRoutes
44		where Self : Sized
45{
46	fn into_routes (self) -> hss::Routes;
47}
48
49
50
51
52pub struct StaticRouteDebug {
53	pub debug : Box<dyn fmt::Debug + Send + Sync>,
54}
55
56
57impl StaticRouteDebug {
58	
59	pub fn new (_debug : impl fmt::Debug + Send + Sync + 'static) -> Self {
60		Self {
61				debug : Box::new (_debug),
62			}
63	}
64	
65	pub fn from_str_static (_description : &'static str) -> Self {
66		struct Description (&'static str);
67		impl fmt::Debug for Description {
68			fn fmt (&self, _formatter : &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
69				_formatter.write_str (self.0)
70			}
71		}
72		let _description = Description (_description);
73		Self::new (_description)
74	}
75}
76
77
78impl fmt::Debug for StaticRouteDebug {
79	
80	fn fmt (&self, _formatter : &mut fmt::Formatter) -> Result<(), fmt::Error> {
81		self.debug.deref () .fmt (_formatter)
82	}
83}
84