Skip to main content

first_str

Function first_str 

Source
pub fn first_str<'a>(
    fields: &'a HashMap<String, Vec<String>>,
    key: &str,
) -> Option<&'a str>
Expand description

Get the first value of a field as &str, if present.

ยงExamples

use std::collections::HashMap;
use openstranded_common_helpers::first_str;

let mut fields = HashMap::new();
fields.insert("name".into(), vec!["Wood".into()]);
assert_eq!(first_str(&fields, "name"), Some("Wood"));
assert_eq!(first_str(&fields, "missing"), None);