pub struct SpecCache { /* private fields */ }Expand description
A persistent dirty-fingerprint cache for WidgetSpec lists.
Owns the per-frame fingerprints across rebuilds so that frame-to-frame
changes can be detected even though IcedUiCtx is consumed each frame.
§Design note
iced Element values are not Clone, so elements themselves cannot be
cached — every frame rebuilds the tree. SpecCache tracks whether a
rebuild was triggered by real spec changes, which is useful for diagnostics
and future optimisation work (e.g. skipping work upstream of the iced
build step).
§Example
use std::borrow::Cow;
use oxiui_iced::adapter::{WidgetSpec, SpecCache};
let mut cache = SpecCache::default();
let specs = vec![WidgetSpec::Label(Cow::Borrowed("hello"))];
let changed = cache.sync(&specs);
assert!(changed, "first sync always marks a change");
assert_eq!(cache.rebuild_count(), 1);
let changed2 = cache.sync(&specs);
assert!(!changed2, "identical specs do not trigger a rebuild");
assert_eq!(cache.rebuild_count(), 1);Implementations§
Source§impl SpecCache
impl SpecCache
Sourcepub fn sync(&mut self, specs: &[WidgetSpec]) -> bool
pub fn sync(&mut self, specs: &[WidgetSpec]) -> bool
Compare specs against the cached fingerprints.
Returns true if the spec list has changed since the last call
(length changed, or any fingerprint differs), and increments
rebuild_count by one.
Returns false when the specs are identical to the last call; the
rebuild count is not incremented.
Sourcepub fn rebuild_count(&self) -> usize
pub fn rebuild_count(&self) -> usize
Return the total number of rebuilds recorded since creation.
A “rebuild” is one call to sync that detected a change.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SpecCache
impl RefUnwindSafe for SpecCache
impl Send for SpecCache
impl Sync for SpecCache
impl Unpin for SpecCache
impl UnsafeUnpin for SpecCache
impl UnwindSafe for SpecCache
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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<T> DowncastSync for T
impl<T> DowncastSync for T
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<State, Message> IntoBoot<State, Message> for State
impl<State, Message> IntoBoot<State, Message> for State
Source§fn into_boot(self) -> (State, Task<Message>)
fn into_boot(self) -> (State, Task<Message>)
Application.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 moreimpl<T> MaybeClone for T
impl<T> MaybeDebug for T
impl<T> MaybeSend for Twhere
T: Send,
impl<T> MaybeSync for Twhere
T: Sync,
Source§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
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().