Skip to main content

qubit_fs/directory/
list_scope.rs

1// =============================================================================
2//    Copyright (c) 2026 Haixing Hu.
3//
4//    SPDX-License-Identifier: Apache-2.0
5//
6//    Licensed under the Apache License, Version 2.0.
7// =============================================================================
8//! Explicit resource-prefix and configured-namespace listing scopes.
9
10use crate::path::Path;
11
12/// Selects the portion of one configured filesystem to enumerate.
13///
14/// A flat [`Path`](Self::Path) scope is a raw key prefix. A hierarchical path
15/// denotes a directory. [`Namespace`](Self::Namespace) is available only for
16/// flat path semantics and never expands beyond the configured filesystem.
17///
18/// # Examples
19///
20/// ```
21/// use qubit_fs::Path;
22/// use qubit_fs::directory::ListScope;
23/// let scope = ListScope::Path(Path::parse_literal("reports/")?);
24/// assert_eq!(scope.path().map(Path::as_str), Some("reports/"));
25/// assert!(ListScope::Namespace.path().is_none());
26/// # Ok::<(), qubit_fs::FsError>(())
27/// ```
28#[derive(Clone, Debug, Eq, PartialEq)]
29#[non_exhaustive]
30pub enum ListScope {
31    /// Enumerates a directory or raw key prefix using its existing path rules.
32    Path(Path),
33    /// Enumerates the entire configured flat namespace without an empty path.
34    Namespace,
35}
36
37impl ListScope {
38    /// Returns the resource prefix, or `None` for a whole namespace query.
39    #[inline]
40    #[must_use]
41    pub const fn path(&self) -> Option<&Path> {
42        match self {
43            Self::Path(path) => Some(path),
44            Self::Namespace => None,
45        }
46    }
47}