Struct yaccas::arguments::Value [] [src]

pub struct Value { /* fields omitted */ }

An argument which represents a value of a specific type.

Example

use yaccas::arguments::{Argument, Value};
use yaccas::parser::{Parser, Result};
use yaccas::scanner::Unix;

// This option will be modified by the value
let mut will_be_46 = 0u32;

{
    let mut parser = Parser::default();
    let value = Value::new::<u32>();

    parser.register(&["val"], Argument::with_callback(value, | value | {
        will_be_46 = value.get_value::<u32>().expect("This will only be executed if the parsing was successful!");
    }));

    assert_eq!(parser.parse(Unix::new(&["-val", "46"])), Result::Success(Vec::new()));
}

assert_eq!(will_be_46, 46u32);Run

Methods

impl Value
[src]

Creates a new value of a specific type T which implements FromStr.

Example

use yaccas::arguments::Value;

let value = Value::new::<u32>();Run

Creates a new value with a default value.

Example

use yaccas::arguments::Value;

assert!(Value::with_default::<u32, _>("46").is_some());
assert!(Value::with_default::<u32, _>("Not a number!").is_none());Run

Set the value if it is valid.

Example

use yaccas::arguments::Value;

let mut value = Value::new::<u32>();

assert_eq!(value.set_value("Invalid value"), false);
assert_eq!(value.get_value::<u32>(), None);

assert_eq!(value.set_value("46"), true);
assert_eq!(value.get_value::<u32>(), Some(46));Run

Returns the value from type T if possible.

Hint

The type T is checked at runtime to be identical which that from new.

Example

use yaccas::arguments::Value;

let value = Value::with_default::<u32, _>("46").expect("Well, 46 is a number...");

assert_eq!(value.get_value::<u32>(), Some(46));
assert_eq!(value.get_value::<u8>(), None); // See hintRun

Returns if the argument has currently a value.

Trait Implementations

impl Parsable for Value
[src]