pub struct ViewId(/* private fields */);Expand description
A lightweight, globally-unique view identity. Copy, carries no
reference into the tree, so it can be stored freely (sibling links, focus
stacks, capture handlers). Identity is ViewId equality.
Global view-identity minter.
§Why this exists
A view tree needs links in every direction: each view to its parent, each view to its siblings, and each group to its focused/selected child. Rust forbids aliased mutable references, so those links cannot all be live pointers. tvision-rs splits them into two clean pieces:
- Downward ownership is a tree — a
Groupownschildren: Vec<Box<dyn View>>. - Up/sideways links become
ViewIdhandles — a lightweight identity that can be stored cheaply anywhere without borrowing the tree.
A ViewId is not an index into any store. It is a globally-unique
identity, minted once at Group::insert and
stamped into the view’s own ViewState. Resolving a
ViewId back to a &mut dyn View is a tree-walk
(View::find_mut) performed by the downward
context, not by the id itself.
§Design
Ids are process-global and monotonic: a single static AtomicU64
counter, never reset, never reused. A stale handle (its view removed) simply
matches nothing in the tree-walk; there is no slot to alias, so no
generational validation is needed (the earlier per-Group generational arena
guarded an ABA hazard that the by-identity child scan cannot have). The
NonZeroU64 gives Option<ViewId> a niche, so it costs no extra size; use
Option<ViewId> (not a sentinel value) to represent “no link / null”. The
u64 space never realistically exhausts (mirrors TimerId).
Ids are process-global and monotonic — minted once at Group::insert,
never reused. A stale handle (its view removed) therefore matches nothing and
simply fails to resolve via View::find_mut;
there is no slot to alias, so no generational validation is needed. The
NonZeroU64 gives Option<ViewId> a niche (no discriminant word). The u64
space never realistically exhausts (mirrors TimerId).
§Turbo Vision heritage
Replaces the raw TView* pointer web (owner, the next/prev sibling
ring, current/selected) with owned tree edges plus by-value identity
handles (deviation D3).
The by-value successor to a raw TView* used for owner / sibling /
current links (deviation D3).
Implementations§
Trait Implementations§
impl Copy for ViewId
impl Eq for ViewId
impl StructuralPartialEq for ViewId
Auto Trait Implementations§
impl Freeze for ViewId
impl RefUnwindSafe for ViewId
impl Send for ViewId
impl Sync for ViewId
impl Unpin for ViewId
impl UnsafeUnpin for ViewId
impl UnwindSafe for ViewId
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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§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
§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.