Struct kas::Id

source ·
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

source

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.

source

pub fn iter(&self) -> WidgetPathIter<'_>

Iterate over path components

source

pub fn path_len(&self) -> usize

Get the path len (number of indices, not storage length)

source

pub fn is_ancestor_of(&self, id: &Id) -> bool

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

source

pub fn common_ancestor(&self, id: &Id) -> Id

Find the most-derived common ancestor

source

pub fn iter_keys_after(&self, id: &Id) -> WidgetPathIter<'_>

source

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.

source

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.

source

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!

source

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

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

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 Clone for Id

source§

fn clone(&self) -> Id

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Id

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl Default for Id

source§

fn default() -> Id

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

impl Display for Id

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl HasId for &Id

source§

fn has_id(self) -> Id

source§

impl HasId for &mut Id

source§

fn has_id(self) -> Id

source§

impl HasId for Id

source§

fn has_id(self) -> Id

source§

impl Hash for Id

source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

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

impl Ord for Id

source§

fn cmp(&self, rhs: &Id) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<'a> PartialEq<&'a Id> for Id

source§

fn eq(&self, rhs: &&Id) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

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

impl<'a> PartialEq<&'a Option<Id>> for Id

source§

fn eq(&self, rhs: &&Option<Id>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

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

impl PartialEq<&str> for Id

source§

fn eq(&self, rhs: &&str) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

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

impl<'a> PartialEq<Option<&'a Id>> for Id

source§

fn eq(&self, rhs: &Option<&'a Id>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

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

impl PartialEq<Option<Id>> for Id

source§

fn eq(&self, rhs: &Option<Id>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

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

impl PartialEq<str> for Id

source§

fn eq(&self, rhs: &str) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

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

impl PartialEq for Id

source§

fn eq(&self, rhs: &Id) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

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

impl PartialOrd for Id

source§

fn partial_cmp(&self, rhs: &Id) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

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

fn le(&self, other: &Rhs) -> bool

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

fn gt(&self, other: &Rhs) -> bool

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

fn ge(&self, other: &Rhs) -> bool

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

impl 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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<S, T> Cast<T> for S
where T: Conv<S>,

§

fn cast(self) -> T

Cast from Self to T Read more
§

fn try_cast(self) -> Result<T, Error>

Try converting from Self to T Read more
§

impl<S, T> CastApprox<T> for S
where T: ConvApprox<S>,

§

fn try_cast_approx(self) -> Result<T, Error>

Try approximate conversion from Self to T Read more
§

fn cast_approx(self) -> T

Cast approximately from Self to T Read more
§

impl<S, T> CastFloat<T> for S
where T: ConvFloat<S>,

§

fn cast_trunc(self) -> T

Cast to integer, truncating Read more
§

fn cast_nearest(self) -> T

Cast to the nearest integer Read more
§

fn cast_floor(self) -> T

Cast the floor to an integer Read more
§

fn cast_ceil(self) -> T

Cast the ceiling to an integer Read more
§

fn try_cast_trunc(self) -> Result<T, Error>

Try converting to integer with truncation Read more
§

fn try_cast_nearest(self) -> Result<T, Error>

Try converting to the nearest integer Read more
§

fn try_cast_floor(self) -> Result<T, Error>

Try converting the floor to an integer Read more
§

fn try_cast_ceil(self) -> Result<T, Error>

Try convert the ceiling to an integer Read more
§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

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

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more