Skip to main content

Resource

Struct Resource 

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

A handle to a bundled resource’s bytes with efficient random read-only access.

The bytes stay valid for the lifetime of the Resource: it owns a guard (an mmap, a native GBytes/QResource/AAsset handle, or an owned buffer) that keeps the backing store alive. Resource is neither Send nor Sync — like the rest of the day runtime it is used on the main/UI thread.

Implementations§

Source§

impl Resource

Source

pub unsafe fn from_raw( ptr: *const u8, len: usize, guard: Box<dyn Any>, ) -> Resource

Build a Resource from a raw byte view plus the guard that owns it. Backends call this from their opener after obtaining a zero-copy pointer from the native resource API.

§Safety

ptr must point to len valid, immutable bytes that remain valid for as long as guard is alive, and guard must own (and keep alive) that backing store.

Source

pub fn from_vec(bytes: Vec<u8>) -> Resource

Build a Resource from owned bytes — the copy fallback for backends that cannot expose a stable pointer into their store (or when a native API only offers a read-into-buffer call).

Source

pub fn len(&self) -> usize

Total byte length of the resource.

Source

pub fn is_empty(&self) -> bool

Whether the resource is empty.

Source

pub fn as_slice(&self) -> &[u8]

A zero-copy view of the full contents. Backed directly by the native store (no allocation, no copy). Wrap in std::io::Cursor for Read/Seek-style access.

Source

pub fn read_at(&self, offset: usize, buf: &mut [u8]) -> usize

Random-access read: copy up to buf.len() bytes starting at offset into buf, returning the number of bytes copied (0 if offset >= len). A direct memcpy from the backing store, no allocation — the efficient primitive for seeking around a large embedded blob.

Source

pub fn to_vec(&self) -> Vec<u8>

Copy the full contents into a freshly allocated Vec.

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.
Day API ↩ Guides· daybrite.dev