@@ -17,7 +17,7 @@ use crate::cache::DirCacheResult;
17
17
#[ cfg( any( feature = "http-async" , feature = "mmap-async-tokio" ) ) ]
18
18
use crate :: cache:: { DirectoryCache , NoCache } ;
19
19
use crate :: directory:: { DirEntry , Directory } ;
20
- use crate :: error:: PmtError ;
20
+ use crate :: error:: { PmtError , PmtResult } ;
21
21
use crate :: header:: { HEADER_SIZE , MAX_INITIAL_BYTES } ;
22
22
#[ cfg( feature = "http-async" ) ]
23
23
use crate :: http:: HttpBackend ;
@@ -37,7 +37,7 @@ impl<B: AsyncBackend + Sync + Send> AsyncPmTilesReader<B, NoCache> {
37
37
/// Creates a new reader from a specified source and validates the provided `PMTiles` archive is valid.
38
38
///
39
39
/// Note: Prefer using `new_with_*` methods.
40
- pub async fn try_from_source ( backend : B ) -> Result < Self , PmtError > {
40
+ pub async fn try_from_source ( backend : B ) -> PmtResult < Self > {
41
41
Self :: try_from_cached_source ( backend, NoCache ) . await
42
42
}
43
43
}
@@ -46,7 +46,7 @@ impl<B: AsyncBackend + Sync + Send, C: DirectoryCache + Sync + Send> AsyncPmTile
46
46
/// Creates a new cached reader from a specified source and validates the provided `PMTiles` archive is valid.
47
47
///
48
48
/// Note: Prefer using `new_with_*` methods.
49
- pub async fn try_from_cached_source ( backend : B , cache : C ) -> Result < Self , PmtError > {
49
+ pub async fn try_from_cached_source ( backend : B , cache : C ) -> PmtResult < Self > {
50
50
// Read the first 127 and up to 16,384 bytes to ensure we can initialize the header and root directory.
51
51
let mut initial_bytes = backend. read ( 0 , MAX_INITIAL_BYTES ) . await ?;
52
52
if initial_bytes. len ( ) < HEADER_SIZE {
@@ -91,7 +91,7 @@ impl<B: AsyncBackend + Sync + Send, C: DirectoryCache + Sync + Send> AsyncPmTile
91
91
///
92
92
/// Note: by spec, this should be valid JSON. This method currently returns a [String].
93
93
/// This may change in the future.
94
- pub async fn get_metadata ( & self ) -> Result < String , PmtError > {
94
+ pub async fn get_metadata ( & self ) -> PmtResult < String > {
95
95
let offset = self . header . metadata_offset as _ ;
96
96
let length = self . header . metadata_length as _ ;
97
97
let metadata = self . backend . read_exact ( offset, length) . await ?;
@@ -103,10 +103,7 @@ impl<B: AsyncBackend + Sync + Send, C: DirectoryCache + Sync + Send> AsyncPmTile
103
103
}
104
104
105
105
#[ cfg( feature = "tilejson" ) ]
106
- pub async fn parse_tilejson (
107
- & self ,
108
- sources : Vec < String > ,
109
- ) -> Result < tilejson:: TileJSON , PmtError > {
106
+ pub async fn parse_tilejson ( & self , sources : Vec < String > ) -> PmtResult < tilejson:: TileJSON > {
110
107
use serde_json:: Value ;
111
108
112
109
let meta = self . get_metadata ( ) . await ?;
@@ -190,20 +187,20 @@ impl<B: AsyncBackend + Sync + Send, C: DirectoryCache + Sync + Send> AsyncPmTile
190
187
entry
191
188
}
192
189
193
- async fn read_directory ( & self , offset : usize , length : usize ) -> Result < Directory , PmtError > {
190
+ async fn read_directory ( & self , offset : usize , length : usize ) -> PmtResult < Directory > {
194
191
let data = self . backend . read_exact ( offset, length) . await ?;
195
192
Self :: read_compressed_directory ( self . header . internal_compression , data) . await
196
193
}
197
194
198
195
async fn read_compressed_directory (
199
196
compression : Compression ,
200
197
bytes : Bytes ,
201
- ) -> Result < Directory , PmtError > {
198
+ ) -> PmtResult < Directory > {
202
199
let decompressed_bytes = Self :: decompress ( compression, bytes) . await ?;
203
200
Directory :: try_from ( decompressed_bytes)
204
201
}
205
202
206
- async fn decompress ( compression : Compression , bytes : Bytes ) -> Result < Bytes , PmtError > {
203
+ async fn decompress ( compression : Compression , bytes : Bytes ) -> PmtResult < Bytes > {
207
204
let mut decompressed_bytes = Vec :: with_capacity ( bytes. len ( ) * 2 ) ;
208
205
match compression {
209
206
Compression :: Gzip => {
@@ -223,7 +220,7 @@ impl AsyncPmTilesReader<HttpBackend, NoCache> {
223
220
/// Creates a new `PMTiles` reader from a URL using the Reqwest backend.
224
221
///
225
222
/// Fails if [url] does not exist or is an invalid archive. (Note: HTTP requests are made to validate it.)
226
- pub async fn new_with_url < U : IntoUrl > ( client : Client , url : U ) -> Result < Self , PmtError > {
223
+ pub async fn new_with_url < U : IntoUrl > ( client : Client , url : U ) -> PmtResult < Self > {
227
224
Self :: new_with_cached_url ( NoCache , client, url) . await
228
225
}
229
226
}
@@ -237,7 +234,7 @@ impl<C: DirectoryCache + Sync + Send> AsyncPmTilesReader<HttpBackend, C> {
237
234
cache : C ,
238
235
client : Client ,
239
236
url : U ,
240
- ) -> Result < Self , PmtError > {
237
+ ) -> PmtResult < Self > {
241
238
let backend = HttpBackend :: try_from ( client, url) ?;
242
239
243
240
Self :: try_from_cached_source ( backend, cache) . await
@@ -249,7 +246,7 @@ impl AsyncPmTilesReader<MmapBackend, NoCache> {
249
246
/// Creates a new `PMTiles` reader from a file path using the async mmap backend.
250
247
///
251
248
/// Fails if [p] does not exist or is an invalid archive.
252
- pub async fn new_with_path < P : AsRef < Path > > ( path : P ) -> Result < Self , PmtError > {
249
+ pub async fn new_with_path < P : AsRef < Path > > ( path : P ) -> PmtResult < Self > {
253
250
Self :: new_with_cached_path ( NoCache , path) . await
254
251
}
255
252
}
@@ -259,7 +256,7 @@ impl<C: DirectoryCache + Sync + Send> AsyncPmTilesReader<MmapBackend, C> {
259
256
/// Creates a new cached `PMTiles` reader from a file path using the async mmap backend.
260
257
///
261
258
/// Fails if [p] does not exist or is an invalid archive.
262
- pub async fn new_with_cached_path < P : AsRef < Path > > ( cache : C , path : P ) -> Result < Self , PmtError > {
259
+ pub async fn new_with_cached_path < P : AsRef < Path > > ( cache : C , path : P ) -> PmtResult < Self > {
263
260
let backend = MmapBackend :: try_from ( path) . await ?;
264
261
265
262
Self :: try_from_cached_source ( backend, cache) . await
@@ -269,10 +266,10 @@ impl<C: DirectoryCache + Sync + Send> AsyncPmTilesReader<MmapBackend, C> {
269
266
#[ async_trait]
270
267
pub trait AsyncBackend {
271
268
/// Reads exactly `length` bytes starting at `offset`
272
- async fn read_exact ( & self , offset : usize , length : usize ) -> Result < Bytes , PmtError > ;
269
+ async fn read_exact ( & self , offset : usize , length : usize ) -> PmtResult < Bytes > ;
273
270
274
271
/// Reads up to `length` bytes starting at `offset`.
275
- async fn read ( & self , offset : usize , length : usize ) -> Result < Bytes , PmtError > ;
272
+ async fn read ( & self , offset : usize , length : usize ) -> PmtResult < Bytes > ;
276
273
}
277
274
278
275
#[ cfg( test) ]
0 commit comments