pub enum Value {
AssociativeArray(Vec<(String, String)>),
Item(String),
List(Vec<String>),
Undefined,
}
Expand description
Variants§
AssociativeArray(Vec<(String, String)>)
The Value::AssociativeArray
variant allows for input data to be
treated as a logical map (with implicit ordering), complying with the
requirements for Level 4 templates defined in
RFC6570 2.3.
Item(String)
The Value::Item
variant allows for simple input data, complying with
the requirements for sub-Level 4 templates defined in
RFC6570 2.3.
List(Vec<String>)
The Value::List
variant allows for input data to be
treated as a logical list (with implicit ordering), complying with the
requirements for Level 4 templates defined in
RFC6570 2.3.
Undefined
The Value::Undefined
variant allows for input data to be explicitly
given as undefined. This is sometimes useful rather than simply omitting
the data.
Implementations§
Source§impl Value
impl Value
Sourcepub fn associative_array<T, U, V>(value: T) -> Self
pub fn associative_array<T, U, V>(value: T) -> Self
Constructs a new Value
from any iterator which produces pairs
(tuples) where both items implement Into<String>
. This may be a
simple array or vec, or a more complex type such as an IndexMap
.
let expected = Value::AssociativeArray(Vec::from_iter([
(String::from("a"), String::from("1")),
(String::from("b"), String::from("2")),
]));
let array = [("a", "1"), ("b", "2")];
assert_eq!(expected, Value::associative_array(array));
let vec = Vec::from_iter(array);
assert_eq!(expected, Value::associative_array(vec));
Sourcepub fn item<T>(value: T) -> Self
pub fn item<T>(value: T) -> Self
Constructs a new Value
from any type which implements
Into<String>
.
let expected = Value::Item(String::from("a"));
let str = "a";
assert_eq!(expected, Value::item(str));
let string = String::from(str);
assert_eq!(expected, Value::item(string));
Examples found in repository?
9fn main() -> Result<(), Box<dyn Error>> {
10 let template = Template::parse("/hello/{name}{/library*}")?;
11 let values = Values::default()
12 .add("name", Value::item("world"))
13 .add("library", Value::list(["uri", "template", "system"]));
14
15 assert_eq!(
16 template.expand(&values)?,
17 "/hello/world/uri/template/system"
18 );
19
20 Ok(())
21}
Sourcepub fn list<T, U>(value: T) -> Self
pub fn list<T, U>(value: T) -> Self
Constructs a new Value
from any iterator which produces items which
implement Into<String>
, such as arrays, vecs, etc.
let expected = Value::List(Vec::from_iter([String::from("a"), String::from("b")]));
let array = ["a", "b"];
assert_eq!(expected, Value::list(array));
let vec = Vec::from_iter(array);
assert_eq!(expected, Value::list(vec));
Examples found in repository?
9fn main() -> Result<(), Box<dyn Error>> {
10 let template = Template::parse("/hello/{name}{/library*}")?;
11 let values = Values::default()
12 .add("name", Value::item("world"))
13 .add("library", Value::list(["uri", "template", "system"]));
14
15 assert_eq!(
16 template.expand(&values)?,
17 "/hello/world/uri/template/system"
18 );
19
20 Ok(())
21}