Skip to main content

tilo_actions/
scope.rs

1//! Where a search looks: a part of what an app shows, by its anchor.
2
3#[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
4pub struct ScopeDecl {
5    pub anchor: String,
6    pub label: String,
7}
8
9impl ScopeDecl {
10    pub fn new(anchor: impl Into<String>, label: impl Into<String>) -> Self {
11        Self {
12            anchor: anchor.into(),
13            label: label.into(),
14        }
15    }
16
17    /// Whether the hit anchored at `anchor` lies inside this scope.
18    #[must_use]
19    pub fn contains(&self, anchor: &str) -> bool {
20        scope_contains(&self.anchor, anchor)
21    }
22}
23
24/// Whether `anchor` is `scope` or lies beneath it in the anchor path.
25#[must_use]
26pub fn scope_contains(scope: &str, anchor: &str) -> bool {
27    anchor
28        .strip_prefix(scope)
29        .is_some_and(|rest| rest.is_empty() || rest.starts_with('/'))
30}