maplibre/
environment.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{
4    io::{
5        apc::AsyncProcedureCall,
6        scheduler::Scheduler,
7        source_client::{HttpClient, SourceClient},
8    },
9    window::MapWindowConfig,
10};
11
12/// The environment defines which types must be injected into maplibre at compile time.
13/// Essentially, this trait implements the
14/// [dependency injection](https://en.wikipedia.org/wiki/Dependency_injection) design pattern.
15/// By instantiating this trait at compile time with concrete types, it is possible to create
16/// different compile-time instances of maplibre.
17///
18/// For example it is possible to change the way tasks are scheduled. It is also possible to change
19/// the HTTP implementation for fetching tiles over the network.
20pub trait Environment: 'static {
21    type MapWindowConfig: MapWindowConfig;
22
23    type AsyncProcedureCall: AsyncProcedureCall<Self::OffscreenKernelEnvironment>;
24
25    type Scheduler: Scheduler;
26
27    type HttpClient: HttpClient;
28
29    type OffscreenKernelEnvironment: OffscreenKernel;
30}
31
32#[derive(Serialize, Deserialize, Clone)]
33pub struct OffscreenKernelConfig {
34    pub cache_directory: Option<String>,
35}
36
37pub trait OffscreenKernel: Send + Sync + 'static {
38    type HttpClient: HttpClient;
39    fn create(config: OffscreenKernelConfig) -> Self;
40
41    fn source_client(&self) -> SourceClient<Self::HttpClient>;
42}