Struct reinda::Assets

source ·
pub struct Assets { /* private fields */ }
Expand description

A set of assets.

This is one of the two main entry points of this library. You create an instance of this type via Assets::new and then retrieve asset data via Assets::get. The macro assets! is the other main entry point of this library. It generates a Setup value at compile time which you have to pass to Assets::new.

Implementations§

source§

impl Assets

source

pub async fn new(setup: Setup, config: Config) -> Result<Self, Error>

Creates a new instance of this type and, in prod mode, prepares all assets.

source

pub async fn get(&self, public_path: &str) -> Result<Option<Bytes>, GetError>

Returns the file contents of the asset referred to by public_path.

The given path is the “public” path, as it is a part of the actual request URI. This doesn’t mean this parameter has to be the full path component from the request URI; you likely want to serve your assets in a subdirectory, like /assets/ which you would have to remove from the URI-path before calling this method. However, for assets with hashed filenames, this method expects the hashed path and not the one you specified in assets!.

If no asset with the specified path exists, Ok(None) is returned. An error is returned in debug mode for a variety of reasons. In prod mode, this method always returns Ok(_). See GetError.

source

pub fn lookup(&self, public_path: &str) -> Option<AssetId>

Resolves the public path to an asset ID. If the public path does not match any asset, None is returned.

source

pub fn asset_ids(&self) -> impl Iterator<Item = AssetId>

Returns an iterator over the IDs of all assets.

source

pub fn asset_info(&self, id: AssetId) -> Info<'_>

Returns meta information about a specific asset. Panics if no asset with the given ID exists.

Trait Implementations§

source§

impl Debug for Assets

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.