Rename HttpClient

This commit is contained in:
Maximilian Ammann 2022-05-26 14:27:27 +02:00
parent 03f38c2725
commit ae36e4f7d4
8 changed files with 21 additions and 21 deletions

View File

@ -1,7 +1,7 @@
use maplibre::error::Error; use maplibre::error::Error;
use maplibre::io::scheduler::ScheduleMethod; use maplibre::io::scheduler::ScheduleMethod;
use maplibre::io::source_client::HTTPClient; use maplibre::io::source_client::{HttpClient, HttpSourceClient};
use maplibre::map_schedule::MapSchedule; use maplibre::map_schedule::{EventuallyMapContext, MapSchedule};
use maplibre::platform::http_client::ReqwestHttpClient; use maplibre::platform::http_client::ReqwestHttpClient;
use maplibre::platform::run_multithreaded; use maplibre::platform::run_multithreaded;
use maplibre::platform::schedule_method::TokioScheduleMethod; use maplibre::platform::schedule_method::TokioScheduleMethod;

View File

@ -1,7 +1,7 @@
use instant::Instant; use instant::Instant;
use maplibre::error::Error; use maplibre::error::Error;
use maplibre::io::scheduler::ScheduleMethod; use maplibre::io::scheduler::ScheduleMethod;
use maplibre::io::source_client::HTTPClient; use maplibre::io::source_client::HttpClient;
use std::borrow::BorrowMut; use std::borrow::BorrowMut;
use winit::event::{ElementState, KeyboardInput, VirtualKeyCode, WindowEvent}; use winit::event::{ElementState, KeyboardInput, VirtualKeyCode, WindowEvent};
use winit::event_loop::ControlFlow; use winit::event_loop::ControlFlow;
@ -69,7 +69,7 @@ impl<MWC, SM, HC> Runnable<MWC, SM, HC> for WinitMapWindow
where where
MWC: MapWindowConfig<MapWindow = WinitMapWindow>, MWC: MapWindowConfig<MapWindow = WinitMapWindow>,
SM: ScheduleMethod, SM: ScheduleMethod,
HC: HTTPClient, HC: HttpClient,
{ {
fn run(mut self, mut map_state: MapSchedule<MWC, SM, HC>, max_frames: Option<u64>) { fn run(mut self, mut map_state: MapSchedule<MWC, SM, HC>, max_frames: Option<u64>) {
let mut last_render_time = Instant::now(); let mut last_render_time = Instant::now();

View File

@ -16,7 +16,7 @@ pub type HTTPClientFactory<HC> = dyn Fn() -> HC;
/// the future "no-thread-safe-futures". Tokio futures are thread-safe. /// the future "no-thread-safe-futures". Tokio futures are thread-safe.
#[cfg_attr(feature = "no-thread-safe-futures", async_trait(?Send))] #[cfg_attr(feature = "no-thread-safe-futures", async_trait(?Send))]
#[cfg_attr(not(feature = "no-thread-safe-futures"), async_trait)] #[cfg_attr(not(feature = "no-thread-safe-futures"), async_trait)]
pub trait HTTPClient: Clone + Sync + Send + 'static { pub trait HttpClient: Clone + Sync + Send + 'static {
async fn fetch(&self, url: &str) -> Result<Vec<u8>, Error>; async fn fetch(&self, url: &str) -> Result<Vec<u8>, Error>;
} }
@ -25,7 +25,7 @@ pub trait HTTPClient: Clone + Sync + Send + 'static {
#[derive(Clone)] #[derive(Clone)]
pub struct HttpSourceClient<HC> pub struct HttpSourceClient<HC>
where where
HC: HTTPClient, HC: HttpClient,
{ {
inner_client: HC, inner_client: HC,
} }
@ -35,7 +35,7 @@ where
#[derive(Clone)] #[derive(Clone)]
pub enum SourceClient<HC> pub enum SourceClient<HC>
where where
HC: HTTPClient, HC: HttpClient,
{ {
Http(HttpSourceClient<HC>), Http(HttpSourceClient<HC>),
Mbtiles { Mbtiles {
@ -45,7 +45,7 @@ where
impl<HC> SourceClient<HC> impl<HC> SourceClient<HC>
where where
HC: HTTPClient, HC: HttpClient,
{ {
pub async fn fetch(&self, coords: &WorldTileCoords) -> Result<Vec<u8>, Error> { pub async fn fetch(&self, coords: &WorldTileCoords) -> Result<Vec<u8>, Error> {
match self { match self {
@ -57,7 +57,7 @@ where
impl<HC> HttpSourceClient<HC> impl<HC> HttpSourceClient<HC>
where where
HC: HTTPClient, HC: HttpClient,
{ {
pub fn new(http_client: HC) -> Self { pub fn new(http_client: HC) -> Self {
Self { Self {

View File

@ -17,7 +17,7 @@
//! ``` //! ```
use crate::io::scheduler::{ScheduleMethod, Scheduler}; use crate::io::scheduler::{ScheduleMethod, Scheduler};
use crate::io::source_client::HTTPClient; use crate::io::source_client::HttpClient;
use crate::map_schedule::MapSchedule; use crate::map_schedule::MapSchedule;
use crate::render::settings::{RendererSettings, WgpuSettings}; use crate::render::settings::{RendererSettings, WgpuSettings};
use crate::render::{RenderState, Renderer}; use crate::render::{RenderState, Renderer};
@ -96,7 +96,7 @@ pub struct UninitializedMap<MWC, SM, HC>
where where
MWC: MapWindowConfig, MWC: MapWindowConfig,
SM: ScheduleMethod, SM: ScheduleMethod,
HC: HTTPClient, HC: HttpClient,
{ {
scheduler: Scheduler<SM>, scheduler: Scheduler<SM>,
http_client: HC, http_client: HC,
@ -111,7 +111,7 @@ impl<MWC, SM, HC> UninitializedMap<MWC, SM, HC>
where where
MWC: MapWindowConfig, MWC: MapWindowConfig,
SM: ScheduleMethod, SM: ScheduleMethod,
HC: HTTPClient, HC: HttpClient,
{ {
/// Initializes the whole rendering pipeline for the given configuration. /// Initializes the whole rendering pipeline for the given configuration.
/// Returns the initialized map, ready to be run. /// Returns the initialized map, ready to be run.

View File

@ -5,7 +5,7 @@ use crate::error::Error;
use crate::io::geometry_index::GeometryIndex; use crate::io::geometry_index::GeometryIndex;
use crate::io::scheduler::Scheduler; use crate::io::scheduler::Scheduler;
use crate::io::shared_thread_state::SharedThreadState; use crate::io::shared_thread_state::SharedThreadState;
use crate::io::source_client::{HTTPClient, HttpSourceClient, SourceClient}; use crate::io::source_client::{HttpClient, HttpSourceClient, SourceClient};
use crate::io::tile_cache::TileCache; use crate::io::tile_cache::TileCache;
use crate::io::tile_request_state::TileRequestState; use crate::io::tile_request_state::TileRequestState;
use crate::io::TessellateMessage; use crate::io::TessellateMessage;
@ -80,7 +80,7 @@ pub struct MapSchedule<MWC, SM, HC>
where where
MWC: MapWindowConfig, MWC: MapWindowConfig,
SM: ScheduleMethod, SM: ScheduleMethod,
HC: HTTPClient, HC: HttpClient,
{ {
map_window_config: MWC, map_window_config: MWC,
@ -98,7 +98,7 @@ impl<MWC, SM, HC> MapSchedule<MWC, SM, HC>
where where
MWC: MapWindowConfig, MWC: MapWindowConfig,
SM: ScheduleMethod, SM: ScheduleMethod,
HC: HTTPClient, HC: HttpClient,
{ {
pub fn new( pub fn new(
map_window_config: MWC, map_window_config: MWC,

View File

@ -1,5 +1,5 @@
use crate::error::Error; use crate::error::Error;
use crate::HTTPClient; use crate::HttpClient;
use async_trait::async_trait; use async_trait::async_trait;
use reqwest::{Client, StatusCode}; use reqwest::{Client, StatusCode};
use reqwest_middleware::ClientWithMiddleware; use reqwest_middleware::ClientWithMiddleware;
@ -41,7 +41,7 @@ impl ReqwestHttpClient {
} }
#[async_trait] #[async_trait]
impl HTTPClient for ReqwestHttpClient { impl HttpClient for ReqwestHttpClient {
async fn fetch(&self, url: &str) -> Result<Vec<u8>, Error> { async fn fetch(&self, url: &str) -> Result<Vec<u8>, Error> {
let response = self.client.get(url).send().await?; let response = self.client.get(url).send().await?;
match response.error_for_status() { match response.error_for_status() {

View File

@ -1,6 +1,6 @@
//! Utilities for the window system. //! Utilities for the window system.
use crate::{HTTPClient, MapSchedule, ScheduleMethod}; use crate::{HttpClient, MapSchedule, ScheduleMethod};
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle}; use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
/// Window with a [carte::window::WindowSize]. /// Window with a [carte::window::WindowSize].
@ -25,7 +25,7 @@ pub trait Runnable<MWC, SM, HC>
where where
MWC: MapWindowConfig, MWC: MapWindowConfig,
SM: ScheduleMethod, SM: ScheduleMethod,
HC: HTTPClient, HC: HttpClient,
{ {
fn run(self, map_state: MapSchedule<MWC, SM, HC>, max_frames: Option<u64>); fn run(self, map_state: MapSchedule<MWC, SM, HC>, max_frames: Option<u64>);
} }

View File

@ -1,5 +1,5 @@
use js_sys::{ArrayBuffer, Uint8Array}; use js_sys::{ArrayBuffer, Uint8Array};
use maplibre::io::source_client::HTTPClient; use maplibre::io::source_client::HttpClient;
use wasm_bindgen::prelude::*; use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast; use wasm_bindgen::JsCast;
use wasm_bindgen_futures::JsFuture; use wasm_bindgen_futures::JsFuture;
@ -61,7 +61,7 @@ impl Clone for WHATWGFetchHttpClient {
} }
#[async_trait(?Send)] #[async_trait(?Send)]
impl HTTPClient for WHATWGFetchHttpClient { impl HttpClient for WHATWGFetchHttpClient {
async fn fetch(&self, url: &str) -> Result<Vec<u8>, Error> { async fn fetch(&self, url: &str) -> Result<Vec<u8>, Error> {
self.fetch_bytes(url) self.fetch_bytes(url)
.await .await