#[derive(Debug, Clone)]
pub struct Crumb<CrumbId: Clone> {
pub id: CrumbId,
pub label: String,
pub is_leaf: bool,
}
impl<CrumbId: Clone> Crumb<CrumbId> {
pub fn ancestor(id: CrumbId, label: impl Into<String>) -> Self {
Self {
id,
label: label.into(),
is_leaf: false,
}
}
pub fn leaf(id: CrumbId, label: impl Into<String>) -> Self {
Self {
id,
label: label.into(),
is_leaf: true,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum BreadcrumbAction<CrumbId> {
Pressed(CrumbId),
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn ancestor_constructor_marks_non_leaf() {
let c: Crumb<u32> = Crumb::ancestor(1, "Home");
assert!(!c.is_leaf);
assert_eq!(c.label, "Home");
}
#[test]
fn leaf_constructor_marks_leaf() {
let c: Crumb<u32> = Crumb::leaf(2, "Profile");
assert!(c.is_leaf);
assert_eq!(c.label, "Profile");
}
#[test]
fn breadcrumb_action_carries_id() {
let action: BreadcrumbAction<u32> = BreadcrumbAction::Pressed(1);
assert_eq!(action, BreadcrumbAction::Pressed(1));
}
}