Skip to main content

PendingErrorCell

Struct PendingErrorCell 

Source
pub struct PendingErrorCell(/* private fields */);
Expand description

Interior-mutable slot for the renderer’s pending error-scope value.

This is the euv-engine analog of euv-core’s HandlerRegistryCell (core/src/renderer/registry/struct.rs:62): a single-element Sync wrapper that holds an Option<JsValue> behind an UnsafeCell.

§Why this type exists

WebGpuRenderer::pending_error needs interior mutability because:

  1. pop_error_sync takes &self (the WebGPU hot path cannot be async), but the spawned wasm_bindgen_futures::spawn_local future must mutate the slot to store the resolved Promise<GPUError?> value.
  2. take_last_error also takes &self and drains the slot on the next render tick.

The first implementation used Rc<RefCell<Option<JsValue>>>, which works but pays for:

  • a RefCell::borrow_mut runtime borrow check on every write (the panic path is unreachable in practice — only the spawn_local future and take_last_error ever touch the slot, and they never overlap because the future is a microtask drained before the next render tick).
  • a heap allocation for the RefCell’s borrow state.

The newtype keeps the interior-mutability primitive (Rc), because the spawn_local future needs its own owning handle, but swaps the inner cell from RefCell to UnsafeCell:

  • zero runtime borrow check (the WASM single-threaded scheduler makes the borrow impossible to violate).
  • zero allocation (the cell is just a *mut Option<JsValue> sitting inside the Rc-managed box).

§Sync safety

PendingErrorCell is not Sync by default (UnsafeCell explicitly opts out). We hand-implement Sync for it because the renderer is only ever used in the WASM single-threaded runtime; the Rc ensures the same instance is never shared across threads (it is not Send/Sync either), and the WASM main thread is the only place that ever touches the slot. This matches euv-core’s pattern (unsafe impl Sync for HandlerRegistryCell {}).

If the engine is ever compiled for a multi-threaded target (native, wasm-bindgen-rayon), this unsafe impl Sync is unsound and must be removed.

Implementations§

Source§

impl PendingErrorCell

Source

pub fn new() -> Self

Construct a new, empty pending-error slot.

The inner UnsafeCell<Option<JsValue>> starts as None; the WebGPU pop_error_sync microtask is the only thing that ever writes to it, and take_last_error is the only reader.

Source

pub fn as_ptr(&self) -> *mut Option<JsValue>

Hand out a raw pointer to the inner cell for the wasm_bindgen_futures::spawn_local closure to write through.

§Safety

The returned pointer is only valid for the lifetime of &self, and only safe to write to on the WASM main thread. The caller must guarantee that no other code is reading the same PendingErrorCell concurrently — this is enforced by the single-threaded scheduler: the spawned future is drained before the next render tick’s take_last_error runs.

Trait Implementations§

Source§

impl Default for PendingErrorCell

Source§

fn default() -> Self

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

impl Sync for PendingErrorCell

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.

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

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more