Skip to main content
← PSoXide SDK guides and examples · SDK 80d1c329e977 · All Cargo features enabled; check feature gates before use.

Handle

Struct Handle 

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

A claim on one playing sound, safe to hold across frames.

It names a voice and a generation. Once the sound ends or its voice is stolen the generation moves on and every call with the old handle does nothing, so an engine loop can keep its handle without checking whether it still owns the voice. The generation is 11 bits; a stale handle could alias a live one only after 2048 reallocations of the same voice.

§Example

use psx_sfx::mixer::Handle;

let h = Handle::from_raw(0b00001_00000_00101);
assert_eq!(h.voice(), 5);
assert_eq!(Handle::from_raw(h.raw()), h);

Implementations§

Source§

impl Handle

Source

pub const fn from_raw(raw: u16) -> Self

Rebuild a handle from raw, for a game that stores them in a compact table.

Source

pub const fn raw(self) -> u16

The packed value: voice in the low 5 bits, generation above.

Source

pub const fn voice(self) -> u8

The voice number this handle names.

Source

pub const fn generation(self) -> u16

The generation, 11 bits.

Trait Implementations§

Source§

impl Clone for Handle

Source§

fn clone(&self) -> Handle

Returns a duplicate of the value. Read more
1.0.0§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Handle

Source§

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

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

impl PartialEq for Handle

Source§

fn eq(&self, other: &Handle) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Handle

Source§

impl Eq for Handle

Source§

impl StructuralPartialEq for Handle

Auto Trait Implementations§

§

impl Freeze for Handle

§

impl RefUnwindSafe for Handle

§

impl Send for Handle

§

impl Sync for Handle

§

impl Unpin for Handle

§

impl UnsafeUnpin for Handle

§

impl UnwindSafe for Handle

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> CloneToUninit for T
where T: Clone,

§

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
§

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.