Skip to main content

find

Function find 

Source
pub fn find<'a>(
    objects: &'a [Object],
    kind: &str,
    slug_wanted: &str,
) -> Option<&'a Object>
Expand description

Find the object of a kind whose identity has this slug.

Linear over the kind’s objects, which is what the Cockpit needs (a lookup per request, over at most a few hundred objects of one kind) and what keeps this function free of a cache nobody invalidates.

use majordomus_cli::entity::find;

let objects = vec![object("rule", "project.x@1"), object("adr", "adr-0056")];

let found = find(&objects, "rule", "project-x-1").expect("the slug resolves");
assert_eq!(found.identity, "project.x@1");
// the kind is part of the address, so the same slug under another kind is not it
assert!(find(&objects, "adr", "project-x-1").is_none());
assert!(find(&objects, "rule", "no-such-rule").is_none());