Struct message_format::Args
[−]
[src]
pub struct Args<'a> {
pub name: &'a str,
pub value: Value<'a>,
pub prev: Option<&'a Args<'a>>,
}Holds the arguments being used to format a Message.
This is a linked list. This avoids any allocations for a Vec
or HashMap. There won't be enough arguments to most messages
to make doing linear searches on the arguments costly enough
to matter.
Fields
name | The name of the argument which must match the usage within the message text. |
value | The value of the argument. |
prev | The 'next' argument (which is really the previous since this is a linked list with the last argument first). |
Methods
impl<'a> Args<'a>
fn arg<T: 'a>(&'a self, name: &'a str, value: T) -> Args<'a> where Self: Sized, Value<'a>: From<T>
Add an additional argument. This returns a new value which maintains a link to the old value. You must maintain a reference to the return value for it to remain valid.
This isn't commonly used as arguments are usually set up via the
format_message! or write_message! macros.
use message_format::arg; let args = arg("name", "John"); let args = args.arg("city", "Rome"); assert!(args.get("name").is_some()); assert!(args.get("city").is_some());
fn get(&'a self, name: &str) -> Option<&'a Args<'a>>
Retrieve the argument with the given name.
use message_format::arg; let args = arg("count", 3); let arg = args.get("count").unwrap();
fn value(&'a self) -> &'a Value<'a>
Retrieve the Value wrapper around the argument value.
use message_format::{arg, Value}; let args = arg("count", 3); let arg = args.get("count").unwrap(); if let &Value::Number(count) = arg.value() { assert_eq!(count, 3); } else { panic!("The count was not a number!"); }