Skip to main content

Resources

Struct Resources 

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

One session’s registry. The maps are secondary to the process-wide the process-wide mint (see the module doc), so a lookup that misses is a handle this session never registered or has since removed — never somebody else’s entry.

Implementations§

Source§

impl Resources

Source

pub fn new(session: SessionId) -> Self

The registry for session session; keys come from the process’s mint.

Source

pub fn session(&self) -> SessionId

The session this registry belongs to.

Source

pub fn font_family(&self, id: FontId) -> Option<&str>

The registered family name, if the handle is live here.

Source

pub fn add_image(&mut self, width: u32, height: u32, rgba: Vec<u8>) -> ImageId

Source

pub fn update_image( &mut self, id: ImageId, width: u32, height: u32, rgba: Vec<u8>, ) -> bool

Replaces an image’s pixels in place: the handle is unchanged, so every node declaring it shows the new pixels next frame with no view change; the dimensions may change. From the first update on the image is texture-backed for life. Returns whether the pixels were taken: false for a foreign or removed handle (noted as a miss), and for a buffer that is not width × height × 4 bytes, which changes nothing rather than handing a backend a short upload it would refuse with a validation error — the doors that take bytes from an app check the length first and say so; this is the guard behind them.

Source

pub fn update_image_with( &mut self, id: ImageId, width: u32, height: u32, fill: impl FnOnce(&mut [u8]), ) -> bool

Self::update_image into a buffer the core recycles: fill is handed width × height × 4 bytes to write the new pixels into, and is not called for a foreign or removed handle (noted as a miss), or for a size whose byte count overflows. The bytes it is handed hold an earlier frame’s pixels, not zeros, so fill writes every one. The buffer is the image’s own when no display list still holds it, else the one the previous update replaced, else a new one — so a stream updated every frame, between frames or inside them, allocates at most three times and then never again. The replaced buffer is kept only for an image updated before at the same size, and let go SPARE_FRAMES frames after the last update. What every door that copies an app’s bytes goes through.

Source

pub fn remove_image(&mut self, id: ImageId) -> Option<ImageEntry>

Source

pub fn image(&self, id: ImageId) -> Option<&ImageEntry>

The pixels behind an image handle, if it is live here.

Source

pub fn fragment(&self, id: FragmentId) -> Option<&Arc<str>>

The WGSL behind a fragment handle, if it is live here. A miss is what makes the node draw nothing, and records a foreign handle.

Source

pub fn add_sound(&mut self, bytes: Vec<u8>) -> SoundId

Registers a sound from its encoded file bytes.

Source

pub fn remove_sound(&mut self, id: SoundId) -> Option<SoundEntry>

Source

pub fn has_sounds(&self) -> bool

Whether any sound is registered: what tells an audio backend it will be asked to play something, before it is.

Source

pub fn sound(&self, id: SoundId) -> Option<&Arc<[u8]>>

The encoded bytes behind a sound handle, if it is live here.

Trait Implementations§

Source§

impl Drop for Resources

Source§

fn drop(&mut self)

A session’s handles leave the mint with it, so the slots come back and a process that opens and closes many sessions (a test binary) does not keep every id it ever minted.

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.