Resource

Enum Resource 

Source
pub enum Resource {
    Audio(AudioBuffer),
    F32(Arc<[f32]>),
    F64(Arc<[f64]>),
    Bytes(Arc<[u8]>),
    Text(Arc<str>),
    Any(Arc<dyn Any + Send + Sync>),
}
Expand description

Rust-native resource registry and resource values. A resource stored in the manager.

Variants§

§

Audio(AudioBuffer)

Shared decoded audio buffer.

§

F32(Arc<[f32]>)

Shared floating-point samples.

§

F64(Arc<[f64]>)

Shared double-precision samples.

§

Bytes(Arc<[u8]>)

Raw shared bytes.

§

Text(Arc<str>)

UTF-8 text payload.

§

Any(Arc<dyn Any + Send + Sync>)

Any custom Rust type wrapped in Arc.

Implementations§

Source§

impl Resource

Source

pub fn f32(data: impl Into<Arc<[f32]>>) -> Self

Wraps a f32 slice in an owned shared resource.

Source

pub fn audio(buffer: AudioBuffer) -> Self

Wraps a decoded audio buffer.

Source

pub fn f64(data: impl Into<Arc<[f64]>>) -> Self

Wraps a f64 slice in an owned shared resource.

Source

pub fn bytes(data: impl Into<Arc<[u8]>>) -> Self

Wraps a byte slice in an owned shared resource.

Source

pub fn text(data: impl Into<Arc<str>>) -> Self

Wraps text in an owned shared resource.

Source

pub fn custom<T>(value: T) -> Self
where T: Any + Send + Sync,

Wraps any Send + Sync + 'static Rust value in an opaque resource.

Source

pub fn shared<T>(value: Arc<T>) -> Self
where T: Any + Send + Sync,

Wraps an already shared Rust value in an opaque resource.

Source

pub fn boxed<T>(value: Box<T>) -> Self
where T: Any + Send + Sync,

Wraps a boxed Rust value in an opaque resource.

Source

pub fn kind(&self) -> &'static str

Returns the resource kind for diagnostics.

Source

pub fn as_f32(&self) -> Option<&[f32]>

Attempts to view the resource as shared f32 samples.

Source

pub fn as_audio(&self) -> Option<&AudioBuffer>

Attempts to view the resource as a decoded audio buffer.

Source

pub fn as_f64(&self) -> Option<&[f64]>

Attempts to view the resource as shared f64 samples.

Source

pub fn as_bytes(&self) -> Option<&[u8]>

Attempts to view the resource as bytes.

Source

pub fn as_text(&self) -> Option<&str>

Attempts to view the resource as text.

Source

pub fn downcast<T>(&self) -> Option<Arc<T>>
where T: Any + Send + Sync,

Attempts to downcast an opaque resource to a concrete Rust type.

Trait Implementations§

Source§

impl Clone for Resource

Source§

fn clone(&self) -> Resource

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Resource

Source§

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

Formats the value using the given formatter. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.