Skip to main content

Asset

Trait Asset 

Source
pub trait Asset:
    Read
    + Seek
    + Send {
    // Required method
    fn size(&self) -> Result<u64>;

    // Provided methods
    fn read_all(&mut self) -> Result<Vec<u8>> { ... }
    fn shared_buffer(&self) -> Option<SharedBuffer> { ... }
    fn into_buffer(self: Box<Self>) -> Result<AssetBuffer> { ... }
}
Expand description

Readable asset handle returned by Resolver::open_asset.

This trait abstracts over the underlying storage mechanism (filesystem, in-memory buffer, archive entry, etc.) and provides random-access reading.

Required Methods§

Source

fn size(&self) -> Result<u64>

Returns the total size of the asset in bytes.

Provided Methods§

Source

fn read_all(&mut self) -> Result<Vec<u8>>

Reads the entire asset into a byte buffer.

Source

fn shared_buffer(&self) -> Option<SharedBuffer>

Returns a shared view of the complete asset without consuming it, or None if the asset must be read into a buffer (C++ ArAsset::GetBuffer).

The view starts at offset zero and matches the bytes exposed through Read and Seek for the asset’s lifetime.

Source

fn into_buffer(self: Box<Self>) -> Result<AssetBuffer>

The complete asset as a buffer, consuming the asset: the view shared_buffer returns when it returns one, otherwise what read_all reads. An asset that owns its buffer hands it over.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Asset for Cursor<AssetBuffer>

An asset over a buffer already in hand, as a package entry, a mapped file or the bytes a host keeps in memory are served.

Source§

fn into_buffer(self: Box<Self>) -> Result<AssetBuffer>

Hands the buffer over.

Source§

fn size(&self) -> Result<u64>

Source§

fn shared_buffer(&self) -> Option<SharedBuffer>

Source§

impl Asset for Cursor<Vec<u8>>

Source§

fn into_buffer(self: Box<Self>) -> Result<AssetBuffer>

Hands the buffer over.

Source§

fn size(&self) -> Result<u64>

Source§

impl Asset for File

Source§

fn size(&self) -> Result<u64>

Implementors§