pub struct Node<'a>(/* private fields */);
Expand description
Type-erased widget with input data
This type is a &mut dyn Widget<Data = A>
paired with input data &A
,
where the type A
is erased.
The default implementation of this type uses a boxed trait object.
The unsafe_node
feature enables a more efficient unboxed implementation
(this must make assumptions about VTables beyond what Rust specifies, thus
lacks even the usual programmer-provided verification of unsafe
code).
Implementations§
source§impl<'a> Node<'a>
impl<'a> Node<'a>
sourcepub fn new<T>(widget: &'a mut dyn Widget<Data = T>, data: &'a T) -> Node<'a>where
T: 'a,
pub fn new<T>(widget: &'a mut dyn Widget<Data = T>, data: &'a T) -> Node<'a>where
T: 'a,
Construct
sourcepub fn re<'b>(&'b mut self) -> Node<'b>where
'a: 'b,
pub fn re<'b>(&'b mut self) -> Node<'b>where
'a: 'b,
Reborrow with a new lifetime
Rust allows references like &T
or &mut T
to be “reborrowed” through
coercion: essentially, the pointer is copied under a new, shorter, lifetime.
Until rfcs#1403 lands, reborrows on user types require a method call.
sourcepub fn eq_id<T>(&self, rhs: T) -> bool
pub fn eq_id<T>(&self, rhs: T) -> bool
Test widget identifier for equality
This method may be used to test against Id
, Option<Id>
and Option<&Id>
.
sourcepub fn is_ancestor_of(&self, id: &Id) -> bool
pub fn is_ancestor_of(&self, id: &Id) -> bool
Check whether id
is self or a descendant
This function assumes that id
is a valid widget.
sourcepub fn is_strict_ancestor_of(&self, id: &Id) -> bool
pub fn is_strict_ancestor_of(&self, id: &Id) -> bool
Check whether id
is not self and is a descendant
This function assumes that id
is a valid widget.
sourcepub fn num_children(&self) -> usize
pub fn num_children(&self) -> usize
Get the number of child widgets
Every value in the range 0..self.num_children()
is a valid child
index.
sourcepub fn for_child<R>(
&mut self,
index: usize,
f: impl FnOnce(Node<'_>) -> R
) -> Option<R>
pub fn for_child<R>( &mut self, index: usize, f: impl FnOnce(Node<'_>) -> R ) -> Option<R>
Run f
on some child by index and, if valid, return the result.
Calls the closure and returns Some(result)
exactly when
index < self.num_children()
.
sourcepub fn for_children(&mut self, f: impl FnMut(Node<'_>))
pub fn for_children(&mut self, f: impl FnMut(Node<'_>))
Run a f
on all children
sourcepub fn find_child_index(&self, id: &Id) -> Option<usize>
pub fn find_child_index(&self, id: &Id) -> Option<usize>
Find the child which is an ancestor of this id
, if any
If Some(index)
is returned, this is probably but not guaranteed
to be a valid child index.