Skip to main content

SnapshotCache

Struct SnapshotCache 

Source
pub struct SnapshotCache { /* private fields */ }
Expand description

Per-thread cached reader for a PublishedSnapshot.

arc_swap::Cache::load is wait-free thread-local-cached: when the underlying ArcSwap pointer is unchanged, the load is one Relaxed atomic compare and returns the cached Arc reference at no further cost. When the pointer changes (post-publish), the next load reloads the new Arc and caches it.

Per-thread state. Cache is Send but !Sync. Each reader thread owns its own SnapshotCache; the App’s renderer thread (the editor mainloop) is the canonical user. Multiple threads reading the same document each construct their own cache from clones of the underlying Arc<PublishedSnapshot>.

Backs the §5.6.8 commitment that the read path lives at the hardware floor (~2ns per load) when the writer hasn’t changed the snapshot since the last frame – the common case for a renderer reading multiple times per frame between edits.

Implementations§

Source§

impl SnapshotCache

Source

pub fn new(cell: Arc<PublishedSnapshot>) -> Self

Build a fresh cache from a clone of the published-snapshot cell. The first load() call pulls the current snapshot; subsequent calls reuse the cached Arc until the writer publishes something new.

Source

pub fn load(&mut self) -> &Arc<DocumentSnapshot> ⓘ

Wait-free per-thread-cached load. Returns a reference to the cached Arc<DocumentSnapshot>; clone if the caller needs an owned Arc. Cheaper than cloning – the reference is valid for as long as the cache isn’t loaded again.

Source

pub fn load_arc(&mut self) -> Arc<DocumentSnapshot> ⓘ

Owned-Arc variant for callers that genuinely need to store the snapshot beyond the cache’s borrow lifetime. Costs one Arc bump on top of Self::load; use sparingly.

Trait Implementations§

Source§

impl Debug for SnapshotCache

Source§

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

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

impl Default for SnapshotCache

Placeholder cache for Editor::default() headless / test scaffolding. Backed by a fresh ArcSwap<DocumentSnapshot> cell carrying a default snapshot. Real construction goes through SnapshotCache::new from the document’s PublishedSnapshot::cell_arc(); Editor::new(...) overwrites this before the first frame.

Source§

fn default() -> Self

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

Auto Trait Implementations§

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
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.

Source§

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

Source§

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>,

Source§

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