Skip to main content

ResourceProvider

Trait ResourceProvider 

Source
pub trait ResourceProvider:
    Send
    + Sync
    + 'static {
    // Required method
    fn request(&self, request: ResourceRequest);

    // Provided method
    fn serves(&self, _kind: Kind, _url: &str) -> bool { ... }
}
Expand description

Serves a runtime’s network requests in place of the library.

A closure Fn(ResourceRequest) is a provider that serves every request. The library loads only http and https, so without a resource transform, a request for another scheme that no provider serves fails at once.

Required Methods§

Source

fn request(&self, request: ResourceRequest)

Serves request: answer it with ResourceRequest::respond, or hand it back with ResourceRequest::pass_through, now or later and on any thread. It runs on a thread of the library’s, which waits for it, and so does a replacement of the provider, so it should hand slow work elsewhere.

Provided Methods§

Source

fn serves(&self, _kind: Kind, _url: &str) -> bool

Whether the provider serves a request for a resource of kind at url. The library loads the requests that the provider doesn’t serve.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

impl<F: Fn(ResourceRequest) + Send + Sync + 'static> ResourceProvider for F