pub struct CliArgs {
pub port: Option<String>,
pub thread_count: usize,
pub dir_path: String,
}
Expand description
The options to start the web-server are collected as command line arguments and parsed into a
convinient data structure which is used throughout the program.
The only supported arguments are --port
, --thread
, and --dir-path
.
Fields§
§port: Option<String>
This represents the --port
option which binds the application to the specified port.
When not provided, a random port is automatically assigned and displayed on the command line.
thread_count: usize
This represents the --thread
option which specifies the number of threads to be used for the server.
When not provided, the program defaults to a thread count of 10.
dir_path: String
This represents the --dir-path
option which specifies the root directory of the static files to be served.
It could be relative to the current directory path or an absolute path.
When not provided, the current directory acts as the root directory for the static files.
Implementations§
Source§impl CliArgs
impl CliArgs
Sourcepub fn get() -> CliArgs
pub fn get() -> CliArgs
Returns a struct with options provided to run the server in the command line.
§Allowed command line arguments
--port
- Specifies the port to bind the application to.--threads
- Specifies the number of threads to serve concurrent requests.--dir-path
- Specifies the path where the static files are located.
§Example
use server::process::CliArgs;
use std::env;
// Default port
let args: CliArgs = CliArgs::get();
assert_eq!(args.thread_count, 10);
// Default file path
let env_args: Vec<String> = env::args().collect();
assert_eq!(args.dir_path, env_args.get(0).unwrap().as_str());
// No port
assert_eq!(args.port, None);
§Panics
- Panics if a command line argument is not allowed. Allowed args include
--threads
,--port
,--dir-path
. - Panics if a value is not provided for an argument.
- Panics if the value for
--threads
is not an integer.