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]
.
§Representation
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
.
§Invalid state
When Id
is Default
constructed, it uses a special invalid state.
Any attempt to use or compare such an invalid state will cause a panic.
Widgets are initially constructed with an invalid Id
, then assigned an
Id
when configured (see Events::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 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 to_nzu64(&self) -> NonZeroU64
pub fn to_nzu64(&self) -> NonZeroU64
Convert to a NonZeroU64
representation
This conversion is infallible but not free.
The result may be used in equality checks (with a very small risk of
false positive due to hash collision) and may be passed to
Self::try_from_u64
.
Sourcepub fn try_from_u64(n: u64) -> Option<Id>
pub fn try_from_u64(n: u64) -> Option<Id>
Try converting a u64
to an Id
This method is the inverse of Self::to_nzu64
. Assuming that the
input n
is the result of calling id.to_nzu64().get()
for some id
,
then this method will return:
Some(Id::INVALID)
where!id.is_valid()
Some(id)
whereid
uses the internal (non-allocated) representationSome(id)
whereid
uses an allocated representation and the originalid
still exists (on the same thread).Some(id)
(probably) whereid
uses an allocated representation, has been freed then reconstructed (on the same thread) before calling this method. (There is a tiny chance of hash collision in this case.)
This method will return None
where:
n == 0
- The originating
id
used an allocating representation and has been deallocated without reconstruction - The originating
id
used an allocating representation and was constructed on another thread (excepting the case where anId
with the same hash was constructed on this thread)
Bad / random inputs may yield either None
or Some(bad_id)
and in the
latter case operations on bad_id
may panic, but are memory safe.
Trait Implementations§
Source§impl From<&Id> for NodeId
Available on crate feature accesskit
only.Convert to a NodeId
using Id::to_nzu64
impl From<&Id> for NodeId
accesskit
only.Convert to a NodeId
using Id::to_nzu64
Use Id::try_from_u64
for the inverse conversion.
Source§impl From<Id> for NodeId
Available on crate feature accesskit
only.Convert to a NodeId
using Id::to_nzu64
impl From<Id> for NodeId
accesskit
only.Convert to a NodeId
using Id::to_nzu64
Use Id::try_from_u64
for the inverse conversion.
Source§impl From<Id> for TextOrSource<'static>
impl From<Id> for TextOrSource<'static>
Source§impl Ord for Id
impl Ord for Id
Source§impl PartialOrd for Id
impl PartialOrd for Id
impl Eq for Id
Auto Trait Implementations§
impl Freeze for Id
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
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§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
.Source§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
.Source§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.Source§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.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 moreSource§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()
.