pub struct Id(/* private fields */);Expand description
Widget identifier
All widgets are assigned an identifier which is unique within the window. This type may be tested for equality and order and may be iterated over as a “path” of “key” values.
Formatting an Id via Display prints the the path, for example
#1290a4. Here, # represents the root; each following hexadecimal digit
represents a path component except that digits 8-f are combined with the
following digit(s). Hence, the above path has components 1, 2, 90,
a4. To interpret these values, first subtract 8 from each digit but the
last digit, then read as base-8: [1, 2, 8, 20].
This type is small (64-bit) and non-zero: Option<Id> has the same
size as Id. It is also very cheap to Clone: usually only one if
check, and in the worst case a pointer dereference and ref-count increment.
Paths up to 14 digits long (as printed) are represented internally;
beyond this limit a reference-counted stack allocation is used.
Id is neither Send nor Sync.
Identifiers are assigned when configured and when re-configured
(via Action::RECONFIGURE or ConfigCx::configure).
In most cases values are persistent but this is not guaranteed (e.g.
inserting or removing a child from a List widget will affect the
identifiers of all following children). View-widgets assign path components
based on the data key, thus possibly making identifiers persistent.
Implementations§
source§impl Id
impl Id
sourcepub fn is_valid(&self) -> bool
pub fn is_valid(&self) -> bool
Is the identifier valid?
Default-constructed identifiers are invalid. Comparing invalid ids is considered a logic error and thus will panic in debug builds. This method may be used to check an identifier’s validity.
sourcepub fn iter(&self) -> WidgetPathIter<'_> ⓘ
pub fn iter(&self) -> WidgetPathIter<'_> ⓘ
Iterate over path components
sourcepub fn is_ancestor_of(&self, id: &Self) -> bool
pub fn is_ancestor_of(&self, id: &Self) -> bool
Returns true if self equals id or if id is a descendant of self
sourcepub fn common_ancestor(&self, id: &Self) -> Self
pub fn common_ancestor(&self, id: &Self) -> Self
Find the most-derived common ancestor
pub fn iter_keys_after(&self, id: &Self) -> WidgetPathIter<'_> ⓘ
sourcepub fn next_key_after(&self, id: &Self) -> Option<usize>
pub fn next_key_after(&self, id: &Self) -> Option<usize>
Get first key in path of self path after id
If the path of self starts with the path of id
(id.is_ancestor_of(self)) then this returns the next key in
self’s path (if any). Otherwise, this returns None.
sourcepub fn parent(&self) -> Option<Id>
pub fn parent(&self) -> Option<Id>
Get the parent widget’s identifier, if not root
Note: there is no guarantee that Self::as_u64 on the result will
match that of the original parent identifier.
sourcepub fn make_child(&self, key: usize) -> Self
pub fn make_child(&self, key: usize) -> Self
Make an identifier for the child with the given key
Note: this is not a getter method. Calling multiple times with the same
key may or may not return the same value!
sourcepub fn as_u64(&self) -> u64
pub fn as_u64(&self) -> u64
Convert to a u64
This value should not be interpreted, except as follows:
- it is guaranteed non-zero
- it may be passed to
Self::opt_from_u64 - comparing two
u64values generated this way will mostly work as an equality check of the sourceId, but can return false negatives (only if each id was generated through separate calls toSelf::make_child)
sourcepub fn opt_to_u64(id: Option<&Id>) -> u64
pub fn opt_to_u64(id: Option<&Id>) -> u64
Convert Option<Id> to u64
This value should not be interpreted, except as follows:
- it is zero if and only if
id == None - it may be passed to
Self::opt_from_u64 - comparing two
u64values generated this way will mostly work as an equality check of the sourceId, but can return false negatives (only if each id was generated through separate calls toSelf::make_child)
sourcepub unsafe fn opt_from_u64(n: u64) -> Option<Id>
pub unsafe fn opt_from_u64(n: u64) -> Option<Id>
Convert u64 to Option<Id>
Returns None if and only if n == 0.
Safety
This may only be called with the output of Self::as_u64,
Self::opt_from_u64, or 0.
This is unsafe since Self has a heap-allocated variant. If n looks
like a heap-allocated variant but is not the result of Self::as_u64,
or it is but the source instance of Self and all clones have been
destroyed, then some operations on the result of this method will
attempt to dereference an invalid pointer.
Trait Implementations§
source§impl Ord for Id
impl Ord for Id
source§impl<'a> PartialEq<&'a Option<Id>> for Id
impl<'a> PartialEq<&'a Option<Id>> for Id
source§impl<'a> PartialEq<Option<&'a Id>> for Id
impl<'a> PartialEq<Option<&'a Id>> for Id
source§impl PartialEq<Option<Id>> for Id
impl PartialEq<Option<Id>> for Id
source§impl PartialOrd for Id
impl PartialOrd for Id
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moreimpl Eq for Id
Auto Trait Implementations§
impl RefUnwindSafe for Id
impl !Send for Id
impl !Sync for Id
impl Unpin for Id
impl UnwindSafe for Id
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
§impl<T> CallHasher for T
impl<T> CallHasher for T
source§impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
source§fn try_cast_approx(self) -> Result<T, Error>
fn try_cast_approx(self) -> Result<T, Error>
source§fn cast_approx(self) -> T
fn cast_approx(self) -> T
source§impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
source§fn cast_trunc(self) -> T
fn cast_trunc(self) -> T
source§fn cast_nearest(self) -> T
fn cast_nearest(self) -> T
source§fn cast_floor(self) -> T
fn cast_floor(self) -> T
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.