hyper_simple_server/
main.rs1
2
3use crate::prelude::*;
4
5
6
7
8#[ cfg (feature = "hss-main") ]
9#[ cfg (feature = "hss-handler") ]
10#[ cfg (feature = "hss-server-core") ]
11pub fn main_with_handler (_handler : impl Handler, _configuration : Option<Configuration>, _arguments : Option<CliArguments>) -> ServerResult {
12
13 let _configuration = prepare_configuration (_configuration, _arguments) ?;
14
15 run_with_handler (_handler, _configuration)
16}
17
18#[ cfg (feature = "hss-main") ]
19#[ cfg (feature = "hss-handler") ]
20#[ cfg (feature = "hss-server-core") ]
21pub fn run_with_handler (_handler : impl Handler, mut _configuration : Configuration) -> ServerResult {
22
23 _configuration.handler = Some (HandlerDynArc::new (_handler));
24
25 Server::run_and_wait (_configuration)
26}
27
28
29#[ cfg (feature = "hss-main") ]
30#[ cfg (feature = "hss-handler") ]
31#[ cfg (feature = "hss-server-core") ]
32pub fn main_with_handler_dyn (_handler : impl HandlerDyn, _configuration : Option<Configuration>, _arguments : Option<CliArguments>) -> ServerResult {
33
34 let _configuration = prepare_configuration (_configuration, _arguments) ?;
35
36 run_with_handler_dyn (_handler, _configuration)
37}
38
39#[ cfg (feature = "hss-main") ]
40#[ cfg (feature = "hss-handler") ]
41#[ cfg (feature = "hss-server-core") ]
42pub fn run_with_handler_dyn (_handler : impl HandlerDyn, mut _configuration : Configuration) -> ServerResult {
43
44 _configuration.handler = Some (HandlerDynArc::new (_handler));
45
46 Server::run_and_wait (_configuration)
47}
48
49
50#[ cfg (feature = "hss-main") ]
51#[ cfg (feature = "hss-routes") ]
52#[ cfg (feature = "hss-server-core") ]
53pub fn main_with_routes (_routes : impl Into<Routes>, _configuration : Option<Configuration>, _arguments : Option<CliArguments>) -> ServerResult {
54
55 let _configuration = prepare_configuration (_configuration, _arguments) ?;
56
57 run_with_routes (_routes, _configuration)
58}
59
60#[ cfg (feature = "hss-main") ]
61#[ cfg (feature = "hss-routes") ]
62#[ cfg (feature = "hss-server-core") ]
63pub fn run_with_routes (_routes : impl Into<Routes>, mut _configuration : Configuration) -> ServerResult {
64
65 _configuration.handler = Some (HandlerDynArc::new (_routes.into ()));
66
67 Server::run_and_wait (_configuration)
68}
69
70
71
72
73#[ cfg (feature = "hss-main") ]
74#[ cfg (feature = "hss-server-core") ]
75pub fn prepare_configuration_http (_arguments : Option<CliArguments>) -> ServerResult<Configuration> {
76
77 let _configuration = Configuration::localhost_http () .build () ?;
78
79 prepare_configuration (Some (_configuration), _arguments)
80}
81
82
83#[ cfg (feature = "hss-main") ]
84#[ cfg (feature = "hss-server-core") ]
85#[ cfg (feature = "hss-tls-any") ]
86pub fn prepare_configuration_https (_arguments : Option<CliArguments>) -> ServerResult<Configuration> {
87
88 let _configuration = Configuration::localhost_https () .build () ?;
89
90 prepare_configuration (Some (_configuration), _arguments)
91}
92
93
94#[ cfg (feature = "hss-main") ]
95#[ cfg (feature = "hss-server-core") ]
96pub fn prepare_configuration (_configuration : Option<Configuration>, _arguments : Option<CliArguments>) -> ServerResult<Configuration> {
97
98 let _configuration = if let Some (_configuration) = _configuration {
99 _configuration
100 } else {
101 Configuration::localhost_http () .build () ?
102 };
103
104 #[ cfg (feature = "hss-cli") ]
105 let _configuration = ConfigurationArguments::parse (_configuration, _arguments) ?;
106
107 Ok (_configuration)
108}
109
110
111#[ cfg (feature = "hss-main") ]
112#[ cfg (feature = "hss-server-core") ]
113#[ cfg (feature = "hss-cli") ]
114pub fn prepare_configuration_with_extensions (_configuration : Option<Configuration>, _extensions : impl CliExtensions, _arguments : Option<CliArguments>) -> ServerResult<Configuration> {
115
116 let _configuration = if let Some (_configuration) = _configuration {
117 _configuration
118 } else {
119 Configuration::localhost_http () .build () ?
120 };
121
122 let _configuration = ConfigurationArguments::parse_with_extensions (_configuration, _extensions, _arguments) ?;
123
124 Ok (_configuration)
125}
126