AUDIO
Source snapshot · 12 October 2026

API reference / ravet_foundation::SnapshotMailbox

Struct SnapshotMailbox 

pub struct SnapshotMailbox<const N: usize> { /* private fields */ }
Expand description

Fixed-size, allocation-free coherent snapshots with bounded attempts.

Available on targets with 64-bit atomics. The generation must not wrap during a single read or between reading a snapshot and publishing conditionally. Atomic words and sequential consistency avoid unsynchronized shared storage. Successful writers hold a sequence reservation for N stores, without waiting on readers. A preempted writer makes reads unavailable until it completes; callers must never spin in an audio callback waiting for a snapshot.

use ravet_foundation::{SnapshotMailbox, PublishError};
let mailbox = SnapshotMailbox::new([1.0_f32.to_bits(), 0]);
let before = mailbox.try_read().unwrap();
mailbox.try_publish([0.5_f32.to_bits(), 1]).unwrap();
assert_eq!(mailbox.try_publish_if(before.generation, before.words), Err(PublishError::Stale));
assert_eq!(f32::from_bits(mailbox.try_read().unwrap().words[0]), 0.5);

Implementations§

§

impl<const N: usize> SnapshotMailbox<N>

pub fn new(words: [u32; N]) -> Self

pub fn try_read(&self) -> Option<WordSnapshot<N>>

Return one coherent snapshot or None when a publication overlaps it.

pub fn try_publish(&self, words: [u32; N]) -> Result<u64, PublishError>

Publish a complete snapshot, failing immediately if a writer overlaps.

pub fn try_publish_if( &self, expected: u64, words: [u32; N], ) -> Result<u64, PublishError>

Publish only if no newer snapshot has superseded the caller’s generation. Audio-side reflection uses this to avoid overwriting a concurrent restore.

Auto Trait Implementations§

§

impl<const N: usize> !Freeze for SnapshotMailbox<N>

§

impl<const N: usize> RefUnwindSafe for SnapshotMailbox<N>

§

impl<const N: usize> Send for SnapshotMailbox<N>

§

impl<const N: usize> Sync for SnapshotMailbox<N>

§

impl<const N: usize> Unpin for SnapshotMailbox<N>

§

impl<const N: usize> UnsafeUnpin for SnapshotMailbox<N>

§

impl<const N: usize> UnwindSafe for SnapshotMailbox<N>

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

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, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

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

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

Performs the conversion.
§

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

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

Performs the conversion.