HttpAssetFetch

Struct HttpAssetFetch 

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

HttpAssetFetch is a struct that enables fetching assets from an HTTP endpoint. The root URL represents the base URL to join with paths to form full asset URLs.

Implementations§

Source§

impl HttpAssetFetch

Source

pub fn new(root: &str) -> Result<Self, Box<dyn Error>>

Creates a new HttpAssetFetch with a provided root URL.

§Arguments
  • root: A string representing the root URL for the HTTP request (e.g., “https://example.com”).
§Returns
  • Ok(HttpAssetFetch): If the root URL is valid and successfully parsed.
  • Err(Box<dyn Error>): If the URL is invalid or any error occurs while parsing.
Examples found in repository?
examples/hello_http.rs (lines 19-21)
10fn main() -> Result<(), Box<dyn Error>> {
11    /* ANCHOR: main */
12    let mut database = AssetDatabase::default()
13        .with_protocol(TextAssetProtocol)
14        .with_protocol(BytesAssetProtocol)
15        .with_protocol(BundleAssetProtocol::new("json", |bytes: Vec<u8>| {
16            Ok((serde_json::from_slice::<Value>(&bytes)?,).into())
17        }))
18        // HTTP asset fetch with root URL for assets.
19        .with_fetch(DeferredAssetFetch::new(HttpAssetFetch::new(
20            "https://raw.githubusercontent.com/PsichiX/Keket/refs/heads/master/resources/",
21        )?));
22
23    // Ensure assets exists or start getting fetched.
24    let lorem = database.ensure("text://lorem.txt")?;
25    let json = database.ensure("json://person.json")?;
26    let trash = database.ensure("bytes://trash.bin")?;
27
28    // Wait while database is busy.
29    while database.is_busy() {
30        println!("Waiting for database to be free");
31        println!(
32            "Loading:\n- Lorem Ipsum: {}\n- JSON: {}\n- Bytes: {}",
33            lorem.awaits_async_fetch(&database),
34            json.awaits_async_fetch(&database),
35            trash.awaits_async_fetch(&database)
36        );
37        database.maintain()?;
38    }
39
40    println!("Lorem Ipsum: {}", lorem.access::<&String>(&database));
41    println!("JSON: {:#}", json.access::<&Value>(&database));
42    println!("Bytes: {:?}", trash.access::<&Vec<u8>>(&database));
43
44    // List all assets from HTTP.
45    for (asset_path, url) in database.storage.query::<true, (&AssetPath, &Url)>() {
46        println!("Asset: `{asset_path}` at url: `{url}`");
47    }
48    /* ANCHOR_END: main */
49
50    Ok(())
51}

Trait Implementations§

Source§

impl AssetFetch for HttpAssetFetch

Source§

fn load_bytes( &self, path: AssetPath<'_>, ) -> Result<DynamicBundle, Box<dyn Error>>

Loads the raw bytes of an asset given its path. Read more
Source§

fn maintain(&mut self, storage: &mut World) -> Result<(), Box<dyn Error>>

Maintains the fetcher’s state. Read more

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> Finalize for T

Source§

unsafe fn finalize_raw(data: *mut ())

Safety Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> Component for T
where T: Send + Sync + 'static,

Source§

impl<T> ErasedDestructor for T
where T: 'static,