Macro searchspot::vec_from_params
[−]
[src]
macro_rules! vec_from_params { ($params:expr, $param:expr) => { ... }; }
Given a Map
, return a Vec<_>
that contains all the items
wrapped inside the Value
s.
Since iron/params
returns Result<Map, ParamsError>
(where
Map
is defined as BTreeMap<String, Value>
) and we're asked to
provide VectorOfTerms<String>::build_terms()
a Vec<String>
,
we need to assert that it is_ok()
and eventually retrieving
its value using the convertion trait FromValue
.
Either if the convertion result is_none()
because of an error
or we originally got a ParamsError
, an empty Vec<String>
will
be returned.
Otherwise, the output will be a Vec<String>
fill with all the
returned String
s found inside the query string.
let mut params = Map::new(); params.assign("work_roles[]", Value::String("Fullstack".into())).unwrap(); params.assign("work_roles[]", Value::String("DevOps".into())).unwrap(); let work_roles: Vec<String> = vec_from_params!(params, "work_roles"); assert_eq!(work_roles, vec!["Fullstack", "DevOps"]);
let work_roles: Vec<String> = vec_from_params!(Map::new(), "work_roles"); assert_eq!(work_roles, Vec::<String>::new());