Skip to main content

TreeRow

Struct TreeRow 

Source
pub struct TreeRow<K, T> {
    pub key: K,
    pub item: T,
    pub depth: usize,
    pub has_children: Option<bool>,
}
Expand description

One row the app hands to a TreeDataSlice, in document (pre-)order.

depth is the indent level (0 = a root). The engine derives each row’s parent, children, and structural depth from the depth sequence: a row’s parent is the nearest preceding row with a strictly smaller depth. The row stream must be well-formed pre-order (a parent precedes its subtree) — the shape any indent-stored outline already has.

Fields§

§key: K

The row’s stable domain identity (entity id, tagged key, …). Must be stable across reloads for expand-state and divergence to survive.

§item: T

The row’s display payload.

§depth: usize

Indent level; 0 is a root.

§has_children: Option<bool>

Declares that this row has children the source has not emitted.

Unset (None) is the ordinary case and the historical behaviour: whether a row has children is derived structurally, from whether any row in the stream names it as parent. That is right for a source that always hands over the whole tree, which is what most of them do.

It is a deadlock for a source that wants to materialise a branch only when it is opened. Such a source emits no children until the row is expanded, so the row is derived childless, so no chevron is drawn, so there is nothing to click, so it is never expanded. StandardTreeItem::on_toggle exists to hang exactly that kind of load off, and without this the callback can never fire.

Set it to Some(true) to promise children that are not there yet: the row draws its chevron, the toggle reaches the app, and the app re-sources with the branch filled in. Some(false) promises the opposite — a leaf, even if the stream happens to contain rows beneath it.

⚠ It is a promise, not a projection. A row that claims children and then produces none on expand opens onto nothing, and the tree cannot detect that for you.

Implementations§

Source§

impl<K, T> TreeRow<K, T>

Source

pub fn new(key: K, item: T, depth: usize) -> Self

Convenience constructor, leaving has_children to be derived from the stream — see the field, and with_children for the case where it cannot be.

Source

pub fn with_children(self, has_children: bool) -> Self

Declare whether this row has children, rather than letting the stream say.

For a source that materialises a branch on expand. See has_children for why a lazy source cannot work without it.

Trait Implementations§

Source§

impl<K: Clone, T: Clone> Clone for TreeRow<K, T>

Source§

fn clone(&self) -> TreeRow<K, T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<K: Debug, T: Debug> Debug for TreeRow<K, T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<K, T> Freeze for TreeRow<K, T>
where K: Freeze, T: Freeze,

§

impl<K, T> RefUnwindSafe for TreeRow<K, T>

§

impl<K, T> Send for TreeRow<K, T>
where K: Send, T: Send,

§

impl<K, T> Sync for TreeRow<K, T>
where K: Sync, T: Sync,

§

impl<K, T> Unpin for TreeRow<K, T>
where K: Unpin, T: Unpin,

§

impl<K, T> UnsafeUnpin for TreeRow<K, T>
where K: UnsafeUnpin, T: UnsafeUnpin,

§

impl<K, T> UnwindSafe for TreeRow<K, T>
where K: UnwindSafe, T: UnwindSafe,

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.

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> 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.