pub struct RecordTree<R> { /* private fields */ }Expand description
Generic tree structure for Altium records.
Provides efficient navigation of parent-child relationships that are encoded via OWNERINDEX in the original flat record list.
Implementations§
Source§impl<R: TreeRecord> RecordTree<R>
impl<R: TreeRecord> RecordTree<R>
Sourcepub fn from_records(records: Vec<R>) -> Self
pub fn from_records(records: Vec<R>) -> Self
Build a tree from a flat list of records using OWNERINDEX relationships.
Records with OWNERINDEX < 0 or >= len are treated as roots.
Sourcepub fn get_by_index(&self, index: usize) -> Option<&R>
pub fn get_by_index(&self, index: usize) -> Option<&R>
Get the record at a specific index.
Sourcepub fn iter(&self) -> impl Iterator<Item = (RecordId, &R)>
pub fn iter(&self) -> impl Iterator<Item = (RecordId, &R)>
Iterate over all records with their IDs.
Sourcepub fn iter_mut(&mut self) -> impl Iterator<Item = (RecordId, &mut R)>
pub fn iter_mut(&mut self) -> impl Iterator<Item = (RecordId, &mut R)>
Iterate over all records mutably with their IDs.
Sourcepub fn roots(&self) -> impl Iterator<Item = (RecordId, &R)>
pub fn roots(&self) -> impl Iterator<Item = (RecordId, &R)>
Get root records (records with no valid parent).
Sourcepub fn root_count(&self) -> usize
pub fn root_count(&self) -> usize
Get the number of root records.
Sourcepub fn parent_id(&self, id: RecordId) -> Option<RecordId>
pub fn parent_id(&self, id: RecordId) -> Option<RecordId>
Get the parent ID of a record (without the record itself).
Sourcepub fn children(&self, id: RecordId) -> impl Iterator<Item = (RecordId, &R)>
pub fn children(&self, id: RecordId) -> impl Iterator<Item = (RecordId, &R)>
Get children of a record.
Sourcepub fn child_count(&self, id: RecordId) -> usize
pub fn child_count(&self, id: RecordId) -> usize
Get the number of children for a record.
Sourcepub fn has_children(&self, id: RecordId) -> bool
pub fn has_children(&self, id: RecordId) -> bool
Check if a record has children.
Sourcepub fn ancestors(&self, id: RecordId) -> impl Iterator<Item = (RecordId, &R)>
pub fn ancestors(&self, id: RecordId) -> impl Iterator<Item = (RecordId, &R)>
Get all ancestors of a record (parent, grandparent, etc.).
Sourcepub fn descendants(&self, id: RecordId) -> impl Iterator<Item = (RecordId, &R)>
pub fn descendants(&self, id: RecordId) -> impl Iterator<Item = (RecordId, &R)>
Get all descendants of a record (children, grandchildren, etc.).
Sourcepub fn walk_depth_first(&self) -> TreeWalker<'_, R> ⓘ
pub fn walk_depth_first(&self) -> TreeWalker<'_, R> ⓘ
Walk the tree depth-first starting from roots.
Sourcepub fn walk_from(&self, id: RecordId) -> TreeWalker<'_, R> ⓘ
pub fn walk_from(&self, id: RecordId) -> TreeWalker<'_, R> ⓘ
Walk the tree depth-first starting from a specific node.
Sourcepub fn find<F>(&self, predicate: F) -> impl Iterator<Item = (RecordId, &R)>
pub fn find<F>(&self, predicate: F) -> impl Iterator<Item = (RecordId, &R)>
Find records matching a predicate.
Sourcepub fn find_first<F>(&self, predicate: F) -> Option<(RecordId, &R)>
pub fn find_first<F>(&self, predicate: F) -> Option<(RecordId, &R)>
Find the first record matching a predicate.
Sourcepub fn path_to_root(&self, id: RecordId) -> Vec<RecordId>
pub fn path_to_root(&self, id: RecordId) -> Vec<RecordId>
Get the path from a record to the root (inclusive).
Sourcepub fn into_records(self) -> Vec<R>
pub fn into_records(self) -> Vec<R>
Consume the tree and return the underlying records.
Sourcepub fn add(&mut self, record: R) -> RecordId
pub fn add(&mut self, record: R) -> RecordId
Add a record to the tree.
Returns the ID of the newly added record.
Trait Implementations§
Source§impl<R: Clone> Clone for RecordTree<R>
impl<R: Clone> Clone for RecordTree<R>
Source§fn clone(&self) -> RecordTree<R>
fn clone(&self) -> RecordTree<R>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<R: Debug> Debug for RecordTree<R>
impl<R: Debug> Debug for RecordTree<R>
Auto Trait Implementations§
impl<R> Freeze for RecordTree<R>
impl<R> RefUnwindSafe for RecordTree<R>where
R: RefUnwindSafe,
impl<R> Send for RecordTree<R>where
R: Send,
impl<R> Sync for RecordTree<R>where
R: Sync,
impl<R> Unpin for RecordTree<R>where
R: Unpin,
impl<R> UnwindSafe for RecordTree<R>where
R: UnwindSafe,
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,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more