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
impl Resource
Sourcepub unsafe fn from_raw(
ptr: *const u8,
len: usize,
guard: Box<dyn Any>,
) -> Resource
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.
Sourcepub fn from_vec(bytes: Vec<u8>) -> Resource
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).
Sourcepub fn as_slice(&self) -> &[u8] ⓘ
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.
Sourcepub fn read_at(&self, offset: usize, buf: &mut [u8]) -> usize
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.