Enum uri_template_system_core::Value
source · pub enum Value {
AssociativeArray(Vec<(String, String)>),
Item(String),
List(Vec<String>),
}Expand description
The Value type is used as the source of content during template expansion,
as part of a Values collection. It maps to the three valid shapes of data
defined by the RFC (a single item, a list of items, or a list of key/value
pairs).
All values are Strings for simplicity of ownership, etc.
Variants§
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 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));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 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));Trait Implementations§
source§impl PartialEq<Value> for Value
impl PartialEq<Value> for Value
impl Eq for Value
impl StructuralEq for Value
impl StructuralPartialEq for Value
Auto Trait Implementations§
impl RefUnwindSafe for Value
impl Send for Value
impl Sync for Value
impl Unpin for Value
impl UnwindSafe for Value
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more