pub struct Runtime { /* private fields */ }Expand description
A runtime: a thread of its own that holds maps, and the resource loading, cache and offline regions that they share.
Every call returns at once. Commands run on the runtime’s thread in the
order they were sent, across the runtime and all its maps, and report
through a Completion. Clone is another handle to the same runtime,
and any thread may use one.
The runtime lives until release or
dispose, or until its last handle and its last map
are dropped. A handler or provider that holds a handle keeps it alive
until then.
Implementations§
Source§impl Runtime
impl Runtime
Sourcepub fn new(options: &RuntimeOptions) -> Result<Runtime, Error>
pub fn new(options: &RuntimeOptions) -> Result<Runtime, Error>
Starts a runtime and its thread.
Fails with ErrorKind::InvalidArgument when the
cache database file can’t be opened or created.
Sourcepub fn create_map(
&self,
options: MapOptions,
) -> Result<(Map, Completion<Applied>), Error>
pub fn create_map( &self, options: MapOptions, ) -> Result<(Map, Completion<Applied>), Error>
Creates a map on the runtime.
The map’s handle is ready at once, and the commands sent to it wait
for the map to be built. If building fails, the completion reports
why and those commands fail with
ErrorKind::InvalidState.
Fails with ErrorKind::InvalidArgument for an
empty size or a pixel ratio that isn’t finite and positive.
Sourcepub fn set_event_handler(
&self,
handler: impl Fn(&[RuntimeEvent]) + Send + Sync + 'static,
) -> Result<Completion<()>, Error>
pub fn set_event_handler( &self, handler: impl Fn(&[RuntimeEvent]) + Send + Sync + 'static, ) -> Result<Completion<()>, Error>
Sends the events of the runtime and its maps to handler, in batches
on the runtime’s thread. It replaces the handler before.
Sourcepub fn clear_event_handler(&self) -> Result<Completion<()>, Error>
pub fn clear_event_handler(&self) -> Result<Completion<()>, Error>
Stops sending events to a handler.
Sourcepub fn set_resource_provider(
&self,
provider: impl ResourceProvider,
) -> Result<Completion<()>, Error>
pub fn set_resource_provider( &self, provider: impl ResourceProvider, ) -> Result<Completion<()>, Error>
Serves the runtime’s network requests that provider serves through
it, and the rest as usual. It replaces the provider before.
Sourcepub fn clear_resource_provider(&self) -> Result<Completion<()>, Error>
pub fn clear_resource_provider(&self) -> Result<Completion<()>, Error>
Removes the resource provider, so the library loads every request itself.
Sourcepub fn set_resource_transform(
&self,
transform: impl Fn(Kind, &str, FinishedCallback) + Send + Sync + 'static,
) -> Result<Completion<()>, Error>
pub fn set_resource_transform( &self, transform: impl Fn(Kind, &str, FinishedCallback) + Send + Sync + 'static, ) -> Result<Completion<()>, Error>
Rewrites the URLs of the runtime’s network requests before they go
out: transform gets the resource’s kind and URL, and answers through
the callback, now or later and on any thread, with the URL to load or
the error to fail the request with. It replaces the transform before.
Sourcepub fn clear_resource_transform(&self) -> Result<Completion<()>, Error>
pub fn clear_resource_transform(&self) -> Result<Completion<()>, Error>
Stops rewriting request URLs.
Sourcepub fn set_http_header_transform(
&self,
transform: impl Fn(Kind, &str) -> HttpHeaders + Send + Sync + 'static,
) -> Result<Completion<()>, Error>
pub fn set_http_header_transform( &self, transform: impl Fn(Kind, &str) -> HttpHeaders + Send + Sync + 'static, ) -> Result<Completion<()>, Error>
Adds the headers that transform returns to the runtime’s HTTP
requests: it gets the resource’s kind and the URL after any resource
transform, and runs for each attempt of a request, which waits for
it. Names that the library manages, such as Range or User-Agent,
are dropped, and a later value of a name replaces an earlier one. It
replaces the transform before.
Fails with ErrorKind::Unsupported in the
browser, where the browser sends the requests.
Sourcepub fn clear_http_header_transform(&self) -> Result<Completion<()>, Error>
pub fn clear_http_header_transform(&self) -> Result<Completion<()>, Error>
Stops adding headers to HTTP requests.
Sourcepub fn run_cache_database_operation(
&self,
operation: CacheDatabaseOperation,
) -> Result<Completion<()>, Error>
pub fn run_cache_database_operation( &self, operation: CacheDatabaseOperation, ) -> Result<Completion<()>, Error>
Runs a maintenance action on the cache database.
Sourcepub fn set_maximum_ambient_cache_size(
&self,
size: u64,
) -> Result<Completion<()>, Error>
pub fn set_maximum_ambient_cache_size( &self, size: u64, ) -> Result<Completion<()>, Error>
Limits the ambient cache to size bytes. Offline regions don’t count
toward it.
Sourcepub fn release(&self) -> Result<Completion<()>, Error>
pub fn release(&self) -> Result<Completion<()>, Error>
Shuts the runtime down. The completion reports when its thread has let go of its maps’ resources and its file sources.
Fails with ErrorKind::InvalidState while the
runtime has maps that aren’t released, or when the runtime was
released already. Every call on the runtime fails the same way after.
Trait Implementations§
Auto Trait Implementations§
impl Forget for Runtime
impl Freeze for Runtime
impl Move for Runtime
impl RefUnwindSafe for Runtime
impl Send for Runtime
impl Sync for Runtime
impl Unpin for Runtime
impl UnsafeUnpin for Runtime
impl UnwindSafe for Runtime
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.