fasm_storage/nav.rs
1//! Directory navigation: the extension trait over [`KvStore`].
2
3use core::future::Future;
4
5use crate::maybe_send::MaybeSend;
6use crate::store::KvStore;
7
8/// Directory navigation over a [`KvStore`].
9///
10/// The data plane addresses data within a directory; this trait
11/// addresses the directories themselves. An implementation lists
12/// directories from the store's own mapping: the flat backends scan one
13/// contiguous mapping range (O(children), not O(subtree keys)), the FDB
14/// backend asks its native directory layer.
15///
16/// All three methods validate their directory path with
17/// [`validate_dir`](crate::validate_dir) before touching the engine.
18/// Their futures follow [`KvStore`]'s portability rule: they are `Send` on
19/// native targets and may remain thread-local on browser wasm.
20pub trait KvDirNav: KvStore {
21 /// List the immediate child directory names under `dir`, as segment
22 /// bytes, sorted ascending.
23 ///
24 /// A missing `dir` yields an empty list, not an error —
25 /// [`dir_exists`](crate::nav::KvDirNav::dir_exists) is how to tell "no children"
26 /// from "not there". Output is sorted at this boundary so the ordering
27 /// is deterministic regardless of the engine's.
28 fn list_dirs(
29 &self,
30 dir: &[&[u8]],
31 ) -> impl Future<Output = Result<Vec<Vec<u8>>, Self::Error>> + MaybeSend;
32
33 /// Whether the directory exists.
34 ///
35 /// "Exists" means the directory is materialised: on the flat backends
36 /// its child row is present (a directory with zero data keys still
37 /// exists); the root exists iff the store's anchor node exists, so a
38 /// fresh, never-written store's root does not; on FDB the layer's
39 /// mapping entry is present.
40 fn dir_exists(
41 &self,
42 dir: &[&[u8]],
43 ) -> impl Future<Output = Result<bool, Self::Error>> + MaybeSend;
44
45 /// Remove `dir` **recursively**: its subdirectories (child rows and
46 /// data) and all of `dir`'s own key data.
47 ///
48 /// A data-destruction operation: everything under `dir` is gone, and it
49 /// cannot be recovered from the store. `Ok(true)` if a directory
50 /// existed and was removed, `Ok(false)` if it did not exist. The root
51 /// `[]` is not removable — [`KeyError::RootNotRemovable`](crate::KeyError::RootNotRemovable).
52 ///
53 /// The whole removal is one transaction on transactional backends.
54 fn remove_dir(
55 &mut self,
56 dir: &[&[u8]],
57 ) -> impl Future<Output = Result<bool, Self::Error>> + MaybeSend;
58}