pub struct WidgetId(_);
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 a WidgetId 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<WidgetId> has the same size as WidgetId. 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.

WidgetId is neither Send nor Sync.

Identifiers are assigned when configured and when re-configured (via TkAction::RECONFIGURE or ConfigMgr::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

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.

Iterate over path components

Returns true if self equals id or if id is a descendant of self

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.

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.

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!

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 source WidgetId, but can return false negatives (only if each id was generated through separate calls to Self::make_child)

Convert Option<WidgetId> 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 source WidgetId, but can return false negatives (only if each id was generated through separate calls to Self::make_child)

Convert u64 to Option<WidgetId>

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.

Construct an iterator, returning indices

This represents the widget’s “path” from the root (window).

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Cast from Self to T Read more

Try converting from Self to T Read more

Try approximate conversion from Self to T Read more

Cast approximately from Self to T Read more

Cast to integer, truncating Read more

Cast to the nearest integer Read more

Cast the floor to an integer Read more

Cast the ceiling to an integer Read more

Try converting to integer with truncation Read more

Try converting to the nearest integer Read more

Try converting the floor to an integer Read more

Try convert the ceiling to an integer Read more

Compare self to key and return true if they are equal.

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.