Skip to main content

ClientAssetFetch

Struct ClientAssetFetch 

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

Client asset fetch from asset server.

Implementations§

Source§

impl ClientAssetFetch

Source

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

Creates a new instance of ClientAssetFetch with the given address.

§Arguments
  • address: A string slice representing the server IP address.
§Returns
  • Ok(ClientAssetFetch) if the initialization is successful.
  • Err(Box<dyn Error>) if any parsing errors occur.
Examples found in repository?
examples/hello_client.rs (lines 15-18)
9fn main() -> Result<(), Box<dyn Error>> {
10    /* ANCHOR: main */
11    let mut database = AssetDatabase::default()
12        .with_protocol(TextAssetProtocol)
13        .with_protocol(BytesAssetProtocol)
14        // Client asset fetch to request files from asset server.
15        .with_fetch(DeferredAssetFetch::new(ClientAssetFetch::new(
16            // IP address of asset server we connect to.
17            "127.0.0.1:8080",
18        )?));
19
20    // Ensure assets exists or start getting fetched.
21    let lorem = database.ensure("text://lorem.txt")?;
22    let trash = database.ensure("bytes://trash.bin")?;
23
24    // Wait till database is busy.
25    while database.is_busy() {
26        println!("Waiting for database to be free");
27        println!(
28            "Loading:\n- Lorem Ipsum: {}\n- Bytes: {}",
29            lorem.has::<AssetAwaitsAsyncFetch>(&database),
30            trash.has::<AssetAwaitsAsyncFetch>(&database)
31        );
32        database.maintain()?;
33    }
34
35    println!("Lorem Ipsum: {}", lorem.access::<&String>(&database));
36    println!("Bytes: {:?}", trash.access::<&Vec<u8>>(&database));
37
38    // List all assets from client.
39    for (asset_path, url) in database.storage.query::<true, (&AssetPath, &Url)>() {
40        println!("Asset: `{asset_path}` at url: `{url}`");
41    }
42
43    println!("Listening for file changes...");
44    loop {
45        database.maintain()?;
46
47        // With storage change detection we can ask for asset entities
48        // that their paths were updated (hot reloading updates them).
49        if let Some(changes) = database.storage.updated() {
50            for entity in changes.iter_of::<AssetPath>() {
51                println!(
52                    "Asset changed: `{}`",
53                    AssetHandle::new(entity).access::<&AssetPath>(&database)
54                );
55            }
56        }
57
58        // Simulate systems that detect particular asset type reload.
59        for entity in database.storage.added().iter_of::<String>() {
60            println!(
61                "Text asset changed: `{}`",
62                AssetHandle::new(entity).access::<&String>(&database)
63            );
64        }
65        for entity in database.storage.added().iter_of::<Vec<u8>>() {
66            println!(
67                "Bytes asset changed: `{:?}`",
68                AssetHandle::new(entity).access::<&Vec<u8>>(&database)
69            );
70        }
71    }
72    /* ANCHOR_END: main */
73}

Trait Implementations§

Source§

impl AssetFetch for ClientAssetFetch

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

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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,