11use crate :: config:: { TileProvider , TileType } ;
22use crate :: map:: coordinates:: { Tile , TilePriority } ;
3- use anyhow:: Result ;
43use log:: { debug, error, trace} ;
54use regex:: Regex ;
65use std:: cmp:: Reverse ;
@@ -79,15 +78,15 @@ impl Ord for PrioritizedTileRequest {
7978/// The interface the cached and non-cached tile loader.
8079pub trait TileLoader {
8180 /// Tries to fetch the tile data asyncroneously.
82- async fn tile_data ( & self , tile : & Tile , source : TileSource ) -> Result < TileData > ;
81+ async fn tile_data ( & self , tile : & Tile , source : TileSource ) -> Result < TileData , TileLoaderError > ;
8382
8483 /// Tries to fetch the tile data with priority.
8584 async fn tile_data_with_priority (
8685 & self ,
8786 tile : & Tile ,
8887 source : TileSource ,
8988 _priority : TilePriority ,
90- ) -> Result < TileData > {
89+ ) -> Result < TileData , TileLoaderError > {
9190 // Default implementation ignores priority
9291 self . tile_data ( tile, source) . await
9392 }
@@ -126,20 +125,20 @@ impl TileCache {
126125}
127126
128127impl TileLoader for TileCache {
129- async fn tile_data ( & self , tile : & Tile , tile_source : TileSource ) -> Result < TileData > {
128+ async fn tile_data ( & self , tile : & Tile , tile_source : TileSource ) -> Result < TileData , TileLoaderError > {
130129 if tile_source == TileSource :: Download {
131- return Err ( TileLoaderError :: TileNotAvailable { tile : * tile } . into ( ) ) ;
130+ return Err ( TileLoaderError :: TileNotAvailable { tile : * tile } ) ;
132131 }
133132 match self . path ( tile) {
134133 Some ( p) => {
135134 if p. exists ( ) {
136135 Ok ( tokio:: fs:: read ( p) . await ?)
137136 } else {
138- Err ( TileLoaderError :: TileNotAvailable { tile : * tile } . into ( ) )
137+ Err ( TileLoaderError :: TileNotAvailable { tile : * tile } )
139138 }
140139 }
141140
142- None => Err ( TileLoaderError :: TileNotAvailable { tile : * tile } . into ( ) ) ,
141+ None => Err ( TileLoaderError :: TileNotAvailable { tile : * tile } ) ,
143142 }
144143 }
145144}
@@ -386,7 +385,7 @@ impl TileDownloader {
386385}
387386
388387impl TileLoader for TileDownloader {
389- async fn tile_data ( & self , tile : & Tile , tile_source : TileSource ) -> Result < TileData > {
388+ async fn tile_data ( & self , tile : & Tile , tile_source : TileSource ) -> Result < TileData , TileLoaderError > {
390389 self
391390 . tile_data_with_priority ( tile, tile_source, TilePriority :: Current )
392391 . await
@@ -397,17 +396,17 @@ impl TileLoader for TileDownloader {
397396 tile : & Tile ,
398397 tile_source : TileSource ,
399398 priority : TilePriority ,
400- ) -> Result < TileData > {
399+ ) -> Result < TileData , TileLoaderError > {
401400 if tile_source == TileSource :: Cache {
402- return Err ( TileLoaderError :: TileNotAvailable { tile : * tile } . into ( ) ) ;
401+ return Err ( TileLoaderError :: TileNotAvailable { tile : * tile } ) ;
403402 }
404403
405404 let download_token =
406405 DownloadManager :: download_with_priority ( & self . download_manager , * tile, priority)
407406 . or_else ( || DownloadManager :: try_next_from_queue ( & self . download_manager ) ) ;
408407
409408 if download_token. is_none ( ) {
410- return Err ( TileLoaderError :: TileDownloadInProgress { tile : * tile } . into ( ) ) ;
409+ return Err ( TileLoaderError :: TileDownloadInProgress { tile : * tile } ) ;
411410 }
412411
413412 let url = self . get_path_for_tile ( tile) ;
@@ -442,7 +441,7 @@ impl TileLoader for TileDownloader {
442441 } ;
443442 debug ! ( "Downloaded {tile:?}." ) ;
444443
445- Ok ( result? )
444+ result
446445 }
447446}
448447
@@ -520,7 +519,7 @@ impl CachedTileLoader {
520519 }
521520 }
522521
523- pub async fn get_from_cache ( & self , tile : & Tile , tile_source : TileSource ) -> Result < TileData > {
522+ pub async fn get_from_cache ( & self , tile : & Tile , tile_source : TileSource ) -> Result < TileData , TileLoaderError > {
524523 self . cache . tile_data ( tile, tile_source) . await
525524 }
526525
@@ -539,7 +538,7 @@ impl CachedTileLoader {
539538 tile : & Tile ,
540539 tile_source : TileSource ,
541540 priority : TilePriority ,
542- ) -> Result < TileData > {
541+ ) -> Result < TileData , TileLoaderError > {
543542 match self
544543 . loader
545544 . tile_data_with_priority ( tile, tile_source, priority)
@@ -548,7 +547,7 @@ impl CachedTileLoader {
548547 Ok ( data) => {
549548 self . cache . cache_tile ( tile, & data) ;
550549 match data. len ( ) {
551- 0 ..=100 => Err ( TileLoaderError :: TileNotAvailable { tile : * tile } . into ( ) ) ,
550+ 0 ..=100 => Err ( TileLoaderError :: TileNotAvailable { tile : * tile } ) ,
552551 _ => Ok ( data) ,
553552 }
554553 }
@@ -589,7 +588,7 @@ impl Default for CachedTileLoader {
589588}
590589
591590impl TileLoader for CachedTileLoader {
592- async fn tile_data ( & self , tile : & Tile , tile_source : TileSource ) -> Result < TileData > {
591+ async fn tile_data ( & self , tile : & Tile , tile_source : TileSource ) -> Result < TileData , TileLoaderError > {
593592 self
594593 . tile_data_with_priority ( tile, tile_source, TilePriority :: Current )
595594 . await
@@ -600,7 +599,7 @@ impl TileLoader for CachedTileLoader {
600599 tile : & Tile ,
601600 tile_source : TileSource ,
602601 priority : TilePriority ,
603- ) -> Result < TileData > {
602+ ) -> Result < TileData , TileLoaderError > {
604603 trace ! ( "Loading tile from file {:?}" , & tile) ;
605604 if let Ok ( data) = self . get_from_cache ( tile, tile_source) . await {
606605 debug ! ( "cache_hit: {tile:?}" ) ;
0 commit comments