Enum uri_template_system_core::Value
source · pub enum Value {
AssociativeArray(Vec<(String, String)>),
Item(String),
List(Vec<String>),
}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.
Implementations§
source§impl Value
impl Value
sourcepub fn associative_array<T, U, V>(value: T) -> Selfwhere
T: IntoIterator<Item = (U, V)>,
U: Into<String>,
V: Into<String>,
pub fn associative_array<T, U, V>(value: T) -> Selfwhere T: IntoIterator<Item = (U, V)>, U: Into<String>, V: Into<String>,
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) -> Selfwhere
T: Into<String>,
pub fn item<T>(value: T) -> Selfwhere T: Into<String>,
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?
9 10 11 12 13 14 15 16 17 18 19 20 21
fn main() -> Result<(), Box<dyn Error>> {
let template = Template::parse("/hello/{name}{/library*}")?;
let values = Values::default()
.add("name", Value::item("world"))
.add("library", Value::list(["uri", "template", "system"]));
assert_eq!(
template.expand(&values)?,
"/hello/world/uri/template/system"
);
Ok(())
}sourcepub fn list<T, U>(value: T) -> Selfwhere
T: IntoIterator<Item = U>,
U: Into<String>,
pub fn list<T, U>(value: T) -> Selfwhere T: IntoIterator<Item = U>, U: Into<String>,
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?
9 10 11 12 13 14 15 16 17 18 19 20 21
fn main() -> Result<(), Box<dyn Error>> {
let template = Template::parse("/hello/{name}{/library*}")?;
let values = Values::default()
.add("name", Value::item("world"))
.add("library", Value::list(["uri", "template", "system"]));
assert_eq!(
template.expand(&values)?,
"/hello/world/uri/template/system"
);
Ok(())
}