pub struct WidgetId(/* private fields */);
Expand description
Unique ID of a widget.
§Name
IDs are only unique for the same process.
You can associate a name
with an ID to give it a persistent identifier.
§Memory
The internal number is a NonZeroU64
, that means that
Option<WidgetId>
and
WidgetId
are the same size as u64
.
§As Hash
The generated internal number has good statistical distribution and can be used as its own hash,
although it is not cryptographically safe, as it is simply a sequential counter scrambled using splitmix64
.
§Static
The unique ID cannot be generated at compile time, but you can use the static_id!
macro to declare
a lazy static that instantiates the ID.
Implementations§
source§impl WidgetId
impl WidgetId
sourcepub fn new_unique() -> WidgetId
pub fn new_unique() -> WidgetId
Generates a new unique ID.
sourcepub fn sequential(self) -> u64
pub fn sequential(self) -> u64
Un-scramble the underlying value to get the original sequential count number.
If two IDs, id0
and id1
where generated by the same thread then id0.sequential() < id1.sequential()
.
sourcepub fn from_raw(raw: u64) -> WidgetId
pub fn from_raw(raw: u64) -> WidgetId
Creates an ID from a raw value.
The value must not be zero, panics if it is, the value must have been provided by get
otherwise
the ID will not be unique.
sourcepub fn from_sequential(num: u64) -> WidgetId
pub fn from_sequential(num: u64) -> WidgetId
Creates an ID from a sequential
number.
§Safety
The value must not be zero, panics if it is, the value must have been provided by sequential
otherwise
the ID will not be unique.
source§impl WidgetId
impl WidgetId
sourcepub fn named(name: impl Into<Txt>) -> WidgetId
pub fn named(name: impl Into<Txt>) -> WidgetId
Get or generate an ID with associated name.
If the name
is already associated with an ID, returns it.
If the name
is new, generates a new ID and associated it with the name.
If name
is an empty string just returns a new ID.
sourcepub fn debug_named(name: impl Into<Txt>) -> WidgetId
pub fn debug_named(name: impl Into<Txt>) -> WidgetId
Calls named
in a debug build and new_unique
in a release build.
sourcepub fn named_new(
name: impl Into<Txt>,
) -> Result<WidgetId, IdNameError<WidgetId>>
pub fn named_new( name: impl Into<Txt>, ) -> Result<WidgetId, IdNameError<WidgetId>>
Generate a new ID with associated name.
If the name
is already associated with an ID, returns the NameUsed
error.
If the name
is an empty string just returns a new ID.
sourcepub fn set_name(self, name: impl Into<Txt>) -> Result<(), IdNameError<WidgetId>>
pub fn set_name(self, name: impl Into<Txt>) -> Result<(), IdNameError<WidgetId>>
Associate a name
with the ID, if it is not named.
If the name
is already associated with a different ID, returns the NameUsed
error.
If the ID is already named, with a name different from name
, returns the AlreadyNamed
error.
If the name
is an empty string or already is the name of the ID, does nothing.
Trait Implementations§
source§impl<'de> Deserialize<'de> for WidgetId
impl<'de> Deserialize<'de> for WidgetId
source§fn deserialize<D>(
deserializer: D,
) -> Result<WidgetId, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<WidgetId, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
source§impl From<WidgetId> for CommandScope
impl From<WidgetId> for CommandScope
source§fn from(id: WidgetId) -> CommandScope
fn from(id: WidgetId) -> CommandScope
source§impl From<WidgetId> for ScrollToTarget
impl From<WidgetId> for ScrollToTarget
source§fn from(widget_id: WidgetId) -> ScrollToTarget
fn from(widget_id: WidgetId) -> ScrollToTarget
source§impl IntoVar<AccessNodeId> for WidgetId
impl IntoVar<AccessNodeId> for WidgetId
source§fn into_var(self) -> <WidgetId as IntoVar<AccessNodeId>>::Var
fn into_var(self) -> <WidgetId as IntoVar<AccessNodeId>>::Var
source§fn into_boxed_var(self) -> Box<dyn VarBoxed<T>>where
Self: Sized,
fn into_boxed_var(self) -> Box<dyn VarBoxed<T>>where
Self: Sized,
BoxedVar<T>
. Read moresource§impl IntoVar<CommandScope> for WidgetId
impl IntoVar<CommandScope> for WidgetId
source§fn into_var(self) -> <WidgetId as IntoVar<CommandScope>>::Var
fn into_var(self) -> <WidgetId as IntoVar<CommandScope>>::Var
source§fn into_boxed_var(self) -> Box<dyn VarBoxed<T>>where
Self: Sized,
fn into_boxed_var(self) -> Box<dyn VarBoxed<T>>where
Self: Sized,
BoxedVar<T>
. Read moresource§impl IntoVar<Option<WidgetId>> for WidgetId
impl IntoVar<Option<WidgetId>> for WidgetId
source§impl IntoVar<ScrollToTarget> for WidgetId
impl IntoVar<ScrollToTarget> for WidgetId
source§fn into_var(self) -> <WidgetId as IntoVar<ScrollToTarget>>::Var
fn into_var(self) -> <WidgetId as IntoVar<ScrollToTarget>>::Var
source§fn into_boxed_var(self) -> Box<dyn VarBoxed<T>>where
Self: Sized,
fn into_boxed_var(self) -> Box<dyn VarBoxed<T>>where
Self: Sized,
BoxedVar<T>
. Read moresource§impl ScrollToTargetProvider for WidgetId
impl ScrollToTargetProvider for WidgetId
source§fn find_target(self) -> Option<WidgetInfo>
fn find_target(self) -> Option<WidgetInfo>
source§impl Serialize for WidgetId
impl Serialize for WidgetId
source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
impl Copy for WidgetId
impl Eq for WidgetId
impl IntoValue<AccessNodeId> for WidgetId
impl IntoValue<CommandScope> for WidgetId
impl IntoValue<Option<WidgetId>> for WidgetId
impl IntoValue<ScrollToTarget> for WidgetId
impl IntoValue<WidgetId> for &'static str
impl IntoValue<WidgetId> for Cow<'static, str>
impl IntoValue<WidgetId> for String
impl IntoValue<WidgetId> for Txt
impl IntoValue<WidgetId> for char
impl NoUninit for WidgetId
impl PodInOption for WidgetId
impl ZeroableInOption for WidgetId
Auto Trait Implementations§
impl Freeze for WidgetId
impl RefUnwindSafe for WidgetId
impl Send for WidgetId
impl Sync for WidgetId
impl Unpin for WidgetId
impl UnwindSafe for WidgetId
Blanket Implementations§
§impl<T> AnyEq for T
impl<T> AnyEq for T
source§impl<T> AnyVarValue for Twhere
T: VarValue,
impl<T> AnyVarValue for Twhere
T: VarValue,
source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
dyn Any
methods.source§fn clone_boxed(&self) -> Box<dyn AnyVarValue>
fn clone_boxed(&self) -> Box<dyn AnyVarValue>
source§fn clone_boxed_var(&self) -> Box<dyn AnyVar>
fn clone_boxed_var(&self) -> Box<dyn AnyVar>
LocalVar<Self>
.source§fn eq_any(&self, other: &(dyn AnyVarValue + 'static)) -> bool
fn eq_any(&self, other: &(dyn AnyVarValue + 'static)) -> bool
self
equals other
.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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> DataNoteValue for T
impl<T> DataNoteValue for T
§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<T> DowncastSync for T
impl<T> DowncastSync for T
§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.source§impl<T> FsChangeNote for T
impl<T> FsChangeNote for T
§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>
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 more