Struct FileTreeStore

Source
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

Source

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());
Source

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");
Source

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);
Source

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);
Source

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)]);
Source

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());
Source

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]);
Source

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);
Source

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());
Source

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]);
Source

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());
Source

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)));
Source

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());
}
Source

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());
}
Source

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());
}
Source

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() });
}
Source

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);
}
Source

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");
Source

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

Source§

fn clone(&self) -> FileTreeStore

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FileTreeStore

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<A> IntoClickAction<A> for A
where A: Clone + 'static,

§

fn into_click_action(self) -> ClickAction<A>

Implements the into_click_action helper used by this module.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> Props for T
where T: Clone + 'static,