get_key

Function get_key 

Source
pub fn get_key<'a>(
    config: &'a Config,
    path: impl AsRef<Path>,
    fields: &HashMap<FieldKey, PathValue>,
) -> Result<Option<&'a FieldKey>, Error>
Expand description

Find a key from a path and fields.

ยงExample

let config = ConfigBuilder::new()
    .add_path_item(PathItemArgs {
        key: "key".try_into().unwrap(),
        path: "/path/to/{thing}".into(),
        parent: None,
        permission: Permission::default(),
        owner: Owner::default(),
        path_type: PathType::default(),
        deferred: false,
        metadata: std::collections::HashMap::new(),
    })
    .unwrap()
    .build()
    .unwrap();

let fields = {
    let mut fields = std::collections::HashMap::new();
    fields.insert("thing".try_into().unwrap(), "value".into());

    fields
};

let path = std::path::PathBuf::from("/path/to/value");
let key = get_key(&config, &path, &fields).unwrap();

assert_eq!(key.map(|k| k.as_str()), Some("key"));