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.
Unless the runtime was released or disposed, the drop of the last of its handles and maps returns once the runtime’s threads have ended: its own and its file sources’. A worker that loads over HTTP and is stuck in a name lookup or a TCP connect is waited for up to a second, then left to end alone. The host’s handlers, providers and transforms that the runtime holds are dropped on its thread meanwhile, so they mustn’t wait for the thread that drops it. A drop on a thread of the library, such as in a handler or callback that the library runs, doesn’t wait: it leaves the runtime’s threads to end alone.
A panic in the work of the runtime or its maps is a bug in the library,
and stops the runtime instead of the process. It logs the panic, the
command that panicked fails with
ErrorKind::Native, those that waited are
cancelled, and the commands sent to the runtime and its maps after fail
with ErrorKind::Native. Release its maps and the runtime 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, with the built-in registrations.
In the browser, the runtime’s thread is the one that calls this, which
a wasm instance has only one of, and the runtime never blocks it: its
commands run in tasks of their own on the browser’s event loop
(web::pump), never inside the call that sends them.
Fails with ErrorKind::InvalidArgument when the
cache database file can’t be opened or created, and in the browser
with ErrorKind::Unsupported for a cache path.
Sourcepub fn with_registry(
options: &RuntimeOptions,
registry: Arc<Registry>,
) -> Result<Runtime, Error>
pub fn with_registry( options: &RuntimeOptions, registry: Arc<Registry>, ) -> Result<Runtime, Error>
Starts a runtime and its thread, whose maps parse their styles
against registry, and whose renderers and tile workers use it. In
the browser, the tile workers’ Web Workers must serve with registries
filled by the same calls (web::tile_worker::serve).
Fails as new does.
Sourcepub fn registry(&self) -> &Arc<Registry> ⓘ
pub fn registry(&self) -> &Arc<Registry> ⓘ
What the runtime’s maps parse against, their renderers draw and their tile workers lay out.
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. An
Accept replaces the one the library sends for tiles and images. 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, and nothing waits for the thread to end after that.
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 !RefUnwindSafe for Runtime
impl !UnwindSafe for Runtime
impl Forget for Runtime
impl Freeze for Runtimewhere
*const ArcInner<RuntimeShared> is !null: Freeze,
PhantomData<ArcInner<RuntimeShared>>: Freeze,
impl Move for Runtime
impl Send for Runtime
impl Sync for Runtime
impl Unpin for Runtime
impl UnsafeUnpin for Runtimewhere
*const ArcInner<RuntimeShared> is !null: UnsafeUnpin,
PhantomData<ArcInner<RuntimeShared>>: UnsafeUnpin,
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§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.