Struct CliArgs

Source
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

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.