pub struct FileTreeStore { /* private fields */ }Expand description
Retained arena, URI index, expansion state, and visible-row cache.
Revisions use saturating addition and therefore never wrap. Provider reads are synchronous. Replacing children removes their URI indexes and expansion state but retains detached arena records so existing IDs never move.
§Examples
use ailloli_ui_fs::{FileEntry, FileKind, FileMetadata, FileUri};
use ailloli_ui_widgets::files::FileTreeStore;
let root = FileEntry::new(FileUri::parse("file:///repo")?, FileMetadata::new(FileKind::Directory));
let store = FileTreeStore::new(root, None);
assert_eq!((store.revision(), store.nodes().len()), (0, 1));Implementations§
Source§impl FileTreeStore
impl FileTreeStore
Sourcepub fn new(root: FileEntry, selected: Option<FileUri>) -> Self
pub fn new(root: FileEntry, selected: Option<FileUri>) -> Self
Creates a revision-zero store whose root has ID zero and is expanded.
selected is stored without checking ancestry or existence. Initial root
load state follows its metadata under default symlink policy. The visible
cache is built immediately and is therefore initially clean.
§Examples
use ailloli_ui_fs::{FileEntry, FileKind, FileMetadata, FileUri};
use ailloli_ui_widgets::files::{FileTreeNodeId, FileTreeStore};
let root = FileEntry::new(FileUri::parse("file:///repo")?, FileMetadata::new(FileKind::Directory));
let mut store = FileTreeStore::new(root, None);
assert_eq!(store.visible_rows(), &[FileTreeNodeId(0)]);
assert!(!store.visible_dirty());Sourcepub fn root_uri(&self) -> &FileUri
pub fn root_uri(&self) -> &FileUri
Borrows the immutable root entry URI.
§Examples
use ailloli_ui_fs::{FileEntry, FileKind, FileMetadata, FileUri};
use ailloli_ui_widgets::files::FileTreeStore;
let root = FileEntry::new(FileUri::parse("file:///repo")?, FileMetadata::new(FileKind::Directory));
let store = FileTreeStore::new(root, None);
assert_eq!(store.root_uri().path(), "/repo");Sourcepub fn revision(&self) -> u64
pub fn revision(&self) -> u64
Returns the monotone, saturating presentation revision.
Selection changes, expansion/cache invalidation, and child merges advance it. A single high-level load can advance it more than once.
§Examples
use ailloli_ui_fs::{FileEntry, FileKind, FileMetadata, FileUri};
use ailloli_ui_widgets::files::FileTreeStore;
let root = FileEntry::new(FileUri::parse("file:///")?, FileMetadata::new(FileKind::Directory));
let mut store = FileTreeStore::new(root, None);
store.set_selected(Some(FileUri::parse("file:///a")?));
assert_eq!(store.revision(), 1);Sourcepub fn nodes(&self) -> &[FileTreeNode]
pub fn nodes(&self) -> &[FileTreeNode]
Borrows the append-only arena, including detached historical records.
Follow the root’s children graph or use Self::to_file_explorer_nodes
when only the current attached tree is desired.
§Examples
use ailloli_ui_fs::{FileEntry, FileKind, FileMetadata, FileUri};
use ailloli_ui_widgets::files::FileTreeStore;
let root = FileEntry::new(FileUri::parse("file:///")?, FileMetadata::new(FileKind::Directory));
let store = FileTreeStore::new(root, None);
assert_eq!(store.nodes().len(), 1);Sourcepub fn visible_rows(&mut self) -> &[FileTreeNodeId]
pub fn visible_rows(&mut self) -> &[FileTreeNodeId]
Rebuilds the root-first visible row cache when dirty, then borrows it.
The root is always present. Descendants appear only below expanded
ancestors. Calling this method clears Self::visible_dirty.
§Examples
use ailloli_ui_fs::{FileEntry, FileKind, FileMetadata, FileUri};
use ailloli_ui_widgets::files::{FileTreeNodeId, FileTreeStore};
let root = FileEntry::new(FileUri::parse("file:///")?, FileMetadata::new(FileKind::Directory));
let mut store = FileTreeStore::new(root, None);
assert_eq!(store.visible_rows(), &[FileTreeNodeId(0)]);Sourcepub fn visible_dirty(&self) -> bool
pub fn visible_dirty(&self) -> bool
Reports whether the visible row cache needs rebuilding.
§Examples
use ailloli_ui_fs::{FileEntry, FileKind, FileMetadata, FileUri};
use ailloli_ui_widgets::files::FileTreeStore;
let root = FileEntry::new(FileUri::parse("file:///")?, FileMetadata::new(FileKind::Directory));
let store = FileTreeStore::new(root, None);
assert!(!store.visible_dirty());Sourcepub fn expanded_uris(&self) -> Vec<FileUri>
pub fn expanded_uris(&self) -> Vec<FileUri>
Clones currently expanded, still-addressable URIs in expansion order.
Detached/out-of-bounds IDs are skipped. The root is included initially
but may be removed through Self::toggle_uri or Self::set_expanded_uris.
§Examples
use ailloli_ui_fs::{FileEntry, FileKind, FileMetadata, FileUri};
use ailloli_ui_widgets::files::FileTreeStore;
let uri = FileUri::parse("file:///repo")?;
let store = FileTreeStore::new(FileEntry::new(uri.clone(), FileMetadata::new(FileKind::Directory)), None);
assert_eq!(store.expanded_uris(), vec![uri]);Sourcepub fn set_selected(&mut self, selected: Option<FileUri>)
pub fn set_selected(&mut self, selected: Option<FileUri>)
Replaces the selected URI and advances revision only when changed.
The URI is not validated against the root or index. Selection changes do not invalidate visible rows; they affect filtering on the next merge.
§Examples
use ailloli_ui_fs::{FileEntry, FileKind, FileMetadata, FileUri};
use ailloli_ui_widgets::files::FileTreeStore;
let root = FileEntry::new(FileUri::parse("file:///")?, FileMetadata::new(FileKind::Directory));
let mut store = FileTreeStore::new(root, None);
store.set_selected(Some(FileUri::parse("file:///a")?));
store.set_selected(Some(FileUri::parse("file:///a")?));
assert_eq!(store.revision(), 1);Sourcepub fn set_expanded_uris(&mut self, expanded: &[FileUri])
pub fn set_expanded_uris(&mut self, expanded: &[FileUri])
Replaces expansion state from known URIs, preserving order and uniqueness.
Unknown URIs are ignored. A changed set invalidates visible rows and advances revision; equal resolved IDs are a no-op.
§Examples
use ailloli_ui_fs::{FileEntry, FileKind, FileMetadata, FileUri};
use ailloli_ui_widgets::files::FileTreeStore;
let uri = FileUri::parse("file:///repo")?;
let mut store = FileTreeStore::new(FileEntry::new(uri.clone(), FileMetadata::new(FileKind::Directory)), None);
store.set_expanded_uris(&[]);
assert!(store.expanded_uris().is_empty() && store.visible_dirty());Sourcepub fn expand_uri(&mut self, uri: &FileUri)
pub fn expand_uri(&mut self, uri: &FileUri)
Adds a known URI to expansion state without loading it.
Unknown/already-expanded URIs are no-ops. A new expansion invalidates visible rows and advances revision.
§Examples
use ailloli_ui_fs::{FileEntry, FileKind, FileMetadata, FileUri};
use ailloli_ui_widgets::files::FileTreeStore;
let uri = FileUri::parse("file:///repo")?;
let mut store = FileTreeStore::new(FileEntry::new(uri.clone(), FileMetadata::new(FileKind::Directory)), None);
store.set_expanded_uris(&[]);
store.expand_uri(&uri);
assert_eq!(store.expanded_uris(), vec![uri]);Sourcepub fn toggle_uri(&mut self, uri: &FileUri, open: bool)
pub fn toggle_uri(&mut self, uri: &FileUri, open: bool)
Opens or closes a known URI without performing provider I/O.
open=true deduplicates through Self::expand_uri semantics;
false removes every matching ID. Unknown/no-change requests are no-ops.
§Examples
use ailloli_ui_fs::{FileEntry, FileKind, FileMetadata, FileUri};
use ailloli_ui_widgets::files::FileTreeStore;
let uri = FileUri::parse("file:///repo")?;
let mut store = FileTreeStore::new(FileEntry::new(uri.clone(), FileMetadata::new(FileKind::Directory)), None);
store.toggle_uri(&uri, false);
assert!(store.expanded_uris().is_empty());Sourcepub fn node_id(&self, uri: &FileUri) -> Option<FileTreeNodeId>
pub fn node_id(&self, uri: &FileUri) -> Option<FileTreeNodeId>
Looks up the currently attached/indexed node for an exact URI.
Detached historical arena nodes are deliberately absent.
§Examples
use ailloli_ui_fs::{FileEntry, FileKind, FileMetadata, FileUri};
use ailloli_ui_widgets::files::{FileTreeNodeId, FileTreeStore};
let uri = FileUri::parse("file:///repo")?;
let store = FileTreeStore::new(FileEntry::new(uri.clone(), FileMetadata::new(FileKind::Directory)), None);
assert_eq!(store.node_id(&uri), Some(FileTreeNodeId(0)));Sourcepub fn load_root(
&mut self,
provider: &dyn FileProvider,
options: FileTreeOptions,
)
pub fn load_root( &mut self, provider: &dyn FileProvider, options: FileTreeOptions, )
Synchronously loads the root unless its state is already clean/active.
Provider errors are retained as DirLoadState::Error rather than
returned. A loaded root is cached and not reread by this method.
§Examples
use ailloli_ui_fs::FileProvider;
use ailloli_ui_widgets::files::{FileTreeOptions, FileTreeStore};
fn load(store: &mut FileTreeStore, provider: &dyn FileProvider) {
store.load_root(provider, FileTreeOptions::default());
}Sourcepub fn ensure_loaded_path(
&mut self,
provider: &dyn FileProvider,
target: &FileUri,
options: FileTreeOptions,
)
pub fn ensure_loaded_path( &mut self, provider: &dyn FileProvider, target: &FileUri, options: FileTreeOptions, )
Loads and expands each currently discoverable root-to-target ancestor.
Traversal stops silently when the target is outside the root or a next ancestor is absent after the preceding load. Provider errors are retained in node state; they are not returned.
§Examples
use ailloli_ui_fs::{FileProvider, FileUri};
use ailloli_ui_widgets::files::{FileTreeOptions, FileTreeStore};
fn reveal(store: &mut FileTreeStore, provider: &dyn FileProvider, target: &FileUri) {
store.ensure_loaded_path(provider, target, FileTreeOptions::default());
}Sourcepub fn preload_depth(
&mut self,
provider: &dyn FileProvider,
depth: usize,
options: FileTreeOptions,
)
pub fn preload_depth( &mut self, provider: &dyn FileProvider, depth: usize, options: FileTreeOptions, )
Synchronously preloads ordinary directories for depth edges from root.
The root itself is always considered, even at depth zero. Symlink policy
treats descendant reads as proactive FileTreeLoadMode
work. The options.max_depth field is not consulted directly here;
callers choose the explicit depth bound.
§Examples
use ailloli_ui_fs::FileProvider;
use ailloli_ui_widgets::files::{FileTreeOptions, FileTreeStore};
fn preload(store: &mut FileTreeStore, provider: &dyn FileProvider) {
store.preload_depth(provider, 2, FileTreeOptions::default());
}Sourcepub fn full_load(
&mut self,
provider: &dyn FileProvider,
options: FileTreeOptions,
)
pub fn full_load( &mut self, provider: &dyn FileProvider, options: FileTreeOptions, )
Preloads from root through options.max_depth edges.
This is a convenience over Self::preload_depth; it does not require
options.load_mode to be FileTreeLoadMode::Full.
§Examples
use ailloli_ui_fs::FileProvider;
use ailloli_ui_widgets::files::{FileTreeOptions, FileTreeStore};
fn load_all(store: &mut FileTreeStore, provider: &dyn FileProvider) {
store.full_load(provider, FileTreeOptions { max_depth: 3, ..FileTreeOptions::default() });
}Sourcepub fn load_directory(
&mut self,
id: FileTreeNodeId,
provider: &dyn FileProvider,
options: FileTreeOptions,
force_reload: bool,
)
pub fn load_directory( &mut self, id: FileTreeNodeId, provider: &dyn FileProvider, options: FileTreeOptions, force_reload: bool, )
Synchronously lists one directory and replaces its retained children.
force_reload rereads only a clean Loaded node; it does not override
NotDirectory or Loading. Unloaded, dirty, and error states retry.
Canonical symlink cycles and provider errors clear children, retain an
error message, dirty visible rows, and return normally.
§Panics
Panics when id is outside this store’s arena.
§Examples
use ailloli_ui_fs::FileProvider;
use ailloli_ui_widgets::files::{FileTreeNodeId, FileTreeOptions, FileTreeStore};
fn reload_root(store: &mut FileTreeStore, provider: &dyn FileProvider) {
store.load_directory(FileTreeNodeId(0), provider, FileTreeOptions::default(), true);
}Sourcepub fn merge_children(
&mut self,
parent: FileTreeNodeId,
entries: Vec<FileEntry>,
options: FileTreeOptions,
)
pub fn merge_children( &mut self, parent: FileTreeNodeId, entries: Vec<FileEntry>, options: FileTreeOptions, )
Filters, sorts, truncates, and replaces one node’s child listing.
Existing child URI indexes and expansion entries are detached recursively;
arena records remain. New IDs append in sorted order. A truncated listing
sets DirLoadState::Dirty; otherwise Loaded.entry_count excludes any
synthetic UI placeholder. Revision advances with saturation and visible
rows become dirty.
§Panics
Panics when parent is outside this store’s arena.
§Examples
use ailloli_ui_fs::{FileEntry, FileKind, FileMetadata, FileUri};
use ailloli_ui_widgets::files::{FileTreeNodeId, FileTreeOptions, FileTreeStore};
let root_uri = FileUri::parse("file:///repo")?;
let mut store = FileTreeStore::new(FileEntry::new(root_uri, FileMetadata::new(FileKind::Directory)), None);
let child = FileEntry::new(FileUri::parse("file:///repo/main.rs")?, FileMetadata::new(FileKind::File));
store.merge_children(FileTreeNodeId(0), vec![child], FileTreeOptions::default());
assert_eq!(store.to_file_explorer_nodes()[0].children[0].name(), "main.rs");Sourcepub fn to_file_explorer_nodes(&self) -> Vec<FileExplorerNode>
pub fn to_file_explorer_nodes(&self) -> Vec<FileExplorerNode>
Clones the currently attached arena graph into one recursive root node.
Loading/error nodes are disabled. Expanded loading/error/dirty nodes gain one synthetic disabled placeholder; collapsed nodes keep real children in the snapshot but omit the placeholder.
§Examples
use ailloli_ui_fs::{FileEntry, FileKind, FileMetadata, FileUri};
use ailloli_ui_widgets::files::FileTreeStore;
let root = FileEntry::new(FileUri::parse("file:///repo")?, FileMetadata::new(FileKind::Directory));
let store = FileTreeStore::new(root, None);
let nodes = store.to_file_explorer_nodes();
assert_eq!((nodes.len(), nodes[0].name()), (1, "repo"));Trait Implementations§
Source§impl Clone for FileTreeStore
impl Clone for FileTreeStore
Source§fn clone(&self) -> FileTreeStore
fn clone(&self) -> FileTreeStore
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for FileTreeStore
impl RefUnwindSafe for FileTreeStore
impl Send for FileTreeStore
impl Sync for FileTreeStore
impl Unpin for FileTreeStore
impl UnwindSafe for FileTreeStore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<A> IntoClickAction<A> for Awhere
A: Clone + 'static,
impl<A> IntoClickAction<A> for Awhere
A: Clone + 'static,
§fn into_click_action(self) -> ClickAction<A>
fn into_click_action(self) -> ClickAction<A>
Implements the into_click_action helper used by this module.