Struct cor_args::ArgHandler

source ·
pub struct ArgHandler<'a> { /* private fields */ }
Expand description

A handler for managing command-line arguments.

This struct is responsible for handling command-line arguments passed to the application. If a value for a given key is not found in the arguments, it delegates the request to the next handler (if provided).

Examples

use cor_args::{ArgHandler, Handler};

// Create a simple `clap` command
let args = clap::Command::new("myapp")
    .arg(clap::Arg::new("example").long("example"))
    .get_matches();

// Create a new ArgHandler for a `clap::ArgMatches`
let handler = ArgHandler::new(&args);

// Add a fallback handler
//let handler = handler.next(some_other_handler.into());

// Handle a configuration request matching the `clap::Arg` name
let value = handler.handle_request("example");

Implementations§

source§

impl<'a> ArgHandler<'a>

source

pub fn new(args: &'a ArgMatches) -> Self

Creates a new ArgHandler with the specified arguments.

Arguments
  • args - The parsed command-line arguments.
Examples
use cor_args::ArgHandler;

let args = clap::Command::new("myapp")
    .arg(clap::Arg::new("config").long("some-option"))
    .get_matches();

let handler = ArgHandler::new(&args);
source

pub fn next(self, handler: Box<dyn Handler>) -> Self

Trait Implementations§

source§

impl<'a> Handler for ArgHandler<'a>

source§

fn handle_request(&self, key: &str) -> Option<String>

Retrieves a value for the specified key from the command-line arguments.

If the key is not found in the arguments, and if a next handler is provided, it delegates the request to the next handler. If there’s no next handler or if the key is not found in both the arguments and the next handler, it returns None.

Arguments
  • key - The key for which the value needs to be retrieved.
Returns

An Option containing the value associated with the key, or None if the key is not found.

source§

impl<'a> Into<Box<dyn Handler + 'a>> for ArgHandler<'a>

source§

fn into(self) -> Box<dyn Handler + 'a>

Converts this type into the (usually inferred) input type.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for ArgHandler<'a>

§

impl<'a> !Send for ArgHandler<'a>

§

impl<'a> !Sync for ArgHandler<'a>

§

impl<'a> Unpin for ArgHandler<'a>

§

impl<'a> !UnwindSafe for ArgHandler<'a>

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>,

§

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>,

§

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.