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: &Id) -> bool
pub fn is_ancestor_of(&self, id: &Id) -> bool
Returns true if self
equals id
or if id
is a descendant of self
sourcepub fn common_ancestor(&self, id: &Id) -> Id
pub fn common_ancestor(&self, id: &Id) -> Id
Find the most-derived common ancestor
pub fn iter_keys_after(&self, id: &Id) -> WidgetPathIter<'_> ⓘ
sourcepub fn next_key_after(&self, id: &Id) -> Option<usize>
pub fn next_key_after(&self, id: &Id) -> 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) -> Id
pub fn make_child(&self, key: usize) -> Id
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
u64
values 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
u64
values 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<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
§fn try_cast_approx(self) -> Result<T, Error>
fn try_cast_approx(self) -> Result<T, Error>
§fn cast_approx(self) -> T
fn cast_approx(self) -> T
§impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
§fn cast_trunc(self) -> T
fn cast_trunc(self) -> T
§fn cast_nearest(self) -> T
fn cast_nearest(self) -> T
§fn cast_floor(self) -> T
fn cast_floor(self) -> T
§fn try_cast_trunc(self) -> Result<T, Error>
fn try_cast_trunc(self) -> Result<T, Error>
§fn try_cast_nearest(self) -> Result<T, Error>
fn try_cast_nearest(self) -> Result<T, Error>
§fn try_cast_floor(self) -> Result<T, Error>
fn try_cast_floor(self) -> Result<T, Error>
§fn try_cast_ceil(self) -> Result<T, Error>
fn try_cast_ceil(self) -> Result<T, Error>
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§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.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian()
.