Lines
100 %
Functions
68.18 %
Branches
//! The account path and the picker order every client shows.
use std::cmp::Ordering;
use std::collections::HashSet;
use uuid::Uuid;
/// The names from the root down to `id`; an account with no name is shown by
/// its id, and a parent cycle ends the walk.
pub fn path_names<'a>(
id: Uuid,
name_of: impl Fn(Uuid) -> Option<&'a str>,
parent_of: impl Fn(Uuid) -> Option<Uuid>,
) -> Vec<String> {
let mut seen = HashSet::new();
let mut names = Vec::new();
let mut next = Some(id);
while let Some(current) = next.filter(|current| seen.insert(*current)) {
names.push(name_of(current).map_or_else(|| current.to_string(), str::to_string));
next = parent_of(current);
}
names.reverse();
names
/// The `:`-joined [`path_names`].
pub fn path_label<'a>(
) -> String {
path_names(id, name_of, parent_of).join(":")
/// Path first, then id: the order of every account picker and list.
#[must_use]
pub fn path_then_id(a: (&str, Uuid), b: (&str, Uuid)) -> Ordering {
a.0.cmp(b.0).then(a.1.cmp(&b.1))