[][src]Struct medusa::Handler

pub struct Handler { /* fields omitted */ }

Struct that defines a CLI option handler in a programmatic way.

Methods

impl Handler[src]

pub fn new() -> Handler[src]

Create a new empty Handler instance.

Example

use medusa::Handler;

// code ...

let mut handler: Handler = Handler::new();

pub fn get_actions(&self) -> Option<&HashMap<String, Variant>>[src]

Get action handler list in form of HashMap from the current Handler instance.

Example

use medusa::{Handler, Variant};

use std::collections::HashMap;

let mut handler: Handler = Handler::new();
// code ...

if let Some(map) = handler.get_actions() {
    println!("Got some actions here!");
} else {
    println!("No actions defined!");
}

pub fn get_hints(&self) -> Option<&HashMap<String, String>>[src]

Get action hint list in form of HashMap from the current Handler instance.

Example

use medusa::{Handler, Variant};

use std::collections::HashMap;

let mut handler: Handler = Handler::new();
// code ...

if let Some(map) = handler.get_hints() {
    println!("Got some hints here!");
} else {
    println!("No hints defined!");
}

pub fn add(&mut self, parameter: String, action: Variant, hint: String)[src]

Add an action for CLI option handler. Note that you must also provide function hint for this option handler. This hint will be shown if arguments passed to this handler are invalid, or when the CLI is calling the --help option. This kind of hint usually a single line of String, but it is not restricted for multi-line String.

Example

use medusa::{Handler, Variant};

// code ...

fn show_help() {
    println!("This is help message!");
}

let mut handler: Handler = Handler::new();
handler.add(
    String::from("--help"),
    Variant::Plain(show_help),
    String::from("Show this help message.")
);

Auto Trait Implementations

impl RefUnwindSafe for Handler

impl Send for Handler

impl Sync for Handler

impl Unpin for Handler

impl UnwindSafe for Handler

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.