Skip to main content

EntryTree

Struct EntryTree 

Source
pub struct EntryTree { /* private fields */ }
Expand description

An in-memory tree of Entrys mirroring one config file.

Entries are addressed by id; nested entries use composite ids (outer:inner, see Entry::path). Entries without an explicit id get a random 6-character base36 id that is persisted on the next write-back.

Structural edits are serialized through an internal lock; individual reads (children, parent walks) take per-entry locks. EntryTree is not bound to any file — pairing it with a crate::LoaderFile is the caller’s (usually the loader’s) job.

Implementations§

Source§

impl EntryTree

Source

pub fn new() -> Self

Create an empty tree.

Source

pub fn root(&self) -> &Entry

The synthetic root holding the top-level entries. It is addressed by the empty id and never returned by EntryTree::resolve.

Source

pub fn top_level(&self) -> Vec<Entry>

Top-level entries in file order.

Source

pub fn entries(&self) -> Vec<Entry>

All entries in depth-first order, parents before children.

Source

pub fn resolve(&self, id: &str) -> Option<Entry>

Look an entry up by (possibly composite) id, e.g. group1:child2.

Source

pub fn serialize(&self) -> Vec<EntryOptions>

Serialize the whole tree back to options, generated ids included.

Source

pub fn create( &self, options: EntryOptions, parent: Option<&Entry>, position: Option<usize>, ) -> Result<Entry>

Create an entry below parent (the tree root when None) at position (appended when None). options.group seeds the child list for group entries. Returns the created entry.

Source

pub fn remove(&self, id: &str) -> Result<Entry>

Detach the entry with the given id and return it with its subtree intact, so the loader can still stop the fibers inside it.

Source

pub fn update_entry( &self, id: &str, options: EntryOptions, new_parent: Option<&Entry>, position: Option<usize>, ) -> Result<Entry>

Update one entry’s options and optionally move it below new_parent (appended unless position is given). The entry id is identity and survives the update; options.id is ignored. options.group re-syncs the entry’s children, reusing existing subtree entries whose ids match.

Source

pub fn update(&self, entries: Vec<EntryOptions>) -> Result<TreeDiff>

Reload the whole tree from new options, reusing existing entries wherever ids match — including entries that moved between groups — and returning what changed.

Entries in the new data without an id cannot be matched and are always created fresh; persist generated ids by writing EntryTree::serialize back to the file.

Trait Implementations§

Source§

impl Default for EntryTree

Source§

fn default() -> Self

Returns the “default value” for a type. 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

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.