@@ -26,7 +26,6 @@ use futures_io::{AsyncRead, AsyncSeek, AsyncWrite};
26
26
use futures_lite:: { ready, Stream } ;
27
27
use std:: {
28
28
io:: SeekFrom ,
29
- mem:: size_of,
30
29
path:: { Path , PathBuf } ,
31
30
pin:: Pin ,
32
31
sync:: Arc ,
@@ -191,32 +190,35 @@ pub trait ErasedAssetReader: Send + Sync + 'static {
191
190
fn read < ' a > (
192
191
& ' a self ,
193
192
path : & ' a Path ,
194
- ) -> BoxedFuture < Result < Box < dyn Reader + ' a > , AssetReaderError > > ;
193
+ ) -> BoxedFuture < ' a , Result < Box < dyn Reader + ' a > , AssetReaderError > > ;
195
194
/// Returns a future to load the full file data at the provided path.
196
195
fn read_meta < ' a > (
197
196
& ' a self ,
198
197
path : & ' a Path ,
199
- ) -> BoxedFuture < Result < Box < dyn Reader + ' a > , AssetReaderError > > ;
198
+ ) -> BoxedFuture < ' a , Result < Box < dyn Reader + ' a > , AssetReaderError > > ;
200
199
/// Returns an iterator of directory entry names at the provided path.
201
200
fn read_directory < ' a > (
202
201
& ' a self ,
203
202
path : & ' a Path ,
204
- ) -> BoxedFuture < Result < Box < PathStream > , AssetReaderError > > ;
203
+ ) -> BoxedFuture < ' a , Result < Box < PathStream > , AssetReaderError > > ;
205
204
/// Returns true if the provided path points to a directory.
206
- fn is_directory < ' a > ( & ' a self , path : & ' a Path ) -> BoxedFuture < Result < bool , AssetReaderError > > ;
205
+ fn is_directory < ' a > (
206
+ & ' a self ,
207
+ path : & ' a Path ,
208
+ ) -> BoxedFuture < ' a , Result < bool , AssetReaderError > > ;
207
209
/// Reads asset metadata bytes at the given `path` into a [`Vec<u8>`]. This is a convenience
208
210
/// function that wraps [`ErasedAssetReader::read_meta`] by default.
209
211
fn read_meta_bytes < ' a > (
210
212
& ' a self ,
211
213
path : & ' a Path ,
212
- ) -> BoxedFuture < Result < Vec < u8 > , AssetReaderError > > ;
214
+ ) -> BoxedFuture < ' a , Result < Vec < u8 > , AssetReaderError > > ;
213
215
}
214
216
215
217
impl < T : AssetReader > ErasedAssetReader for T {
216
218
fn read < ' a > (
217
219
& ' a self ,
218
220
path : & ' a Path ,
219
- ) -> BoxedFuture < Result < Box < dyn Reader + ' a > , AssetReaderError > > {
221
+ ) -> BoxedFuture < ' a , Result < Box < dyn Reader + ' a > , AssetReaderError > > {
220
222
Box :: pin ( async {
221
223
let reader = Self :: read ( self , path) . await ?;
222
224
Ok ( Box :: new ( reader) as Box < dyn Reader > )
@@ -225,7 +227,7 @@ impl<T: AssetReader> ErasedAssetReader for T {
225
227
fn read_meta < ' a > (
226
228
& ' a self ,
227
229
path : & ' a Path ,
228
- ) -> BoxedFuture < Result < Box < dyn Reader + ' a > , AssetReaderError > > {
230
+ ) -> BoxedFuture < ' a , Result < Box < dyn Reader + ' a > , AssetReaderError > > {
229
231
Box :: pin ( async {
230
232
let reader = Self :: read_meta ( self , path) . await ?;
231
233
Ok ( Box :: new ( reader) as Box < dyn Reader > )
@@ -234,16 +236,19 @@ impl<T: AssetReader> ErasedAssetReader for T {
234
236
fn read_directory < ' a > (
235
237
& ' a self ,
236
238
path : & ' a Path ,
237
- ) -> BoxedFuture < Result < Box < PathStream > , AssetReaderError > > {
239
+ ) -> BoxedFuture < ' a , Result < Box < PathStream > , AssetReaderError > > {
238
240
Box :: pin ( Self :: read_directory ( self , path) )
239
241
}
240
- fn is_directory < ' a > ( & ' a self , path : & ' a Path ) -> BoxedFuture < Result < bool , AssetReaderError > > {
242
+ fn is_directory < ' a > (
243
+ & ' a self ,
244
+ path : & ' a Path ,
245
+ ) -> BoxedFuture < ' a , Result < bool , AssetReaderError > > {
241
246
Box :: pin ( Self :: is_directory ( self , path) )
242
247
}
243
248
fn read_meta_bytes < ' a > (
244
249
& ' a self ,
245
250
path : & ' a Path ,
246
- ) -> BoxedFuture < Result < Vec < u8 > , AssetReaderError > > {
251
+ ) -> BoxedFuture < ' a , Result < Vec < u8 > , AssetReaderError > > {
247
252
Box :: pin ( Self :: read_meta_bytes ( self , path) )
248
253
}
249
254
}
@@ -352,115 +357,127 @@ pub trait AssetWriter: Send + Sync + 'static {
352
357
/// as [`AssetWriter`] isn't currently object safe.
353
358
pub trait ErasedAssetWriter : Send + Sync + ' static {
354
359
/// Writes the full asset bytes at the provided path.
355
- fn write < ' a > ( & ' a self , path : & ' a Path ) -> BoxedFuture < Result < Box < Writer > , AssetWriterError > > ;
360
+ fn write < ' a > (
361
+ & ' a self ,
362
+ path : & ' a Path ,
363
+ ) -> BoxedFuture < ' a , Result < Box < Writer > , AssetWriterError > > ;
356
364
/// Writes the full asset meta bytes at the provided path.
357
365
/// This _should not_ include storage specific extensions like `.meta`.
358
366
fn write_meta < ' a > (
359
367
& ' a self ,
360
368
path : & ' a Path ,
361
- ) -> BoxedFuture < Result < Box < Writer > , AssetWriterError > > ;
369
+ ) -> BoxedFuture < ' a , Result < Box < Writer > , AssetWriterError > > ;
362
370
/// Removes the asset stored at the given path.
363
- fn remove < ' a > ( & ' a self , path : & ' a Path ) -> BoxedFuture < Result < ( ) , AssetWriterError > > ;
371
+ fn remove < ' a > ( & ' a self , path : & ' a Path ) -> BoxedFuture < ' a , Result < ( ) , AssetWriterError > > ;
364
372
/// Removes the asset meta stored at the given path.
365
373
/// This _should not_ include storage specific extensions like `.meta`.
366
- fn remove_meta < ' a > ( & ' a self , path : & ' a Path ) -> BoxedFuture < Result < ( ) , AssetWriterError > > ;
374
+ fn remove_meta < ' a > ( & ' a self , path : & ' a Path ) -> BoxedFuture < ' a , Result < ( ) , AssetWriterError > > ;
367
375
/// Renames the asset at `old_path` to `new_path`
368
376
fn rename < ' a > (
369
377
& ' a self ,
370
378
old_path : & ' a Path ,
371
379
new_path : & ' a Path ,
372
- ) -> BoxedFuture < Result < ( ) , AssetWriterError > > ;
380
+ ) -> BoxedFuture < ' a , Result < ( ) , AssetWriterError > > ;
373
381
/// Renames the asset meta for the asset at `old_path` to `new_path`.
374
382
/// This _should not_ include storage specific extensions like `.meta`.
375
383
fn rename_meta < ' a > (
376
384
& ' a self ,
377
385
old_path : & ' a Path ,
378
386
new_path : & ' a Path ,
379
- ) -> BoxedFuture < Result < ( ) , AssetWriterError > > ;
387
+ ) -> BoxedFuture < ' a , Result < ( ) , AssetWriterError > > ;
380
388
/// Removes the directory at the given path, including all assets _and_ directories in that directory.
381
- fn remove_directory < ' a > ( & ' a self , path : & ' a Path ) -> BoxedFuture < Result < ( ) , AssetWriterError > > ;
389
+ fn remove_directory < ' a > (
390
+ & ' a self ,
391
+ path : & ' a Path ,
392
+ ) -> BoxedFuture < ' a , Result < ( ) , AssetWriterError > > ;
382
393
/// Removes the directory at the given path, but only if it is completely empty. This will return an error if the
383
394
/// directory is not empty.
384
395
fn remove_empty_directory < ' a > (
385
396
& ' a self ,
386
397
path : & ' a Path ,
387
- ) -> BoxedFuture < Result < ( ) , AssetWriterError > > ;
398
+ ) -> BoxedFuture < ' a , Result < ( ) , AssetWriterError > > ;
388
399
/// Removes all assets (and directories) in this directory, resulting in an empty directory.
389
400
fn remove_assets_in_directory < ' a > (
390
401
& ' a self ,
391
402
path : & ' a Path ,
392
- ) -> BoxedFuture < Result < ( ) , AssetWriterError > > ;
403
+ ) -> BoxedFuture < ' a , Result < ( ) , AssetWriterError > > ;
393
404
/// Writes the asset `bytes` to the given `path`.
394
405
fn write_bytes < ' a > (
395
406
& ' a self ,
396
407
path : & ' a Path ,
397
408
bytes : & ' a [ u8 ] ,
398
- ) -> BoxedFuture < Result < ( ) , AssetWriterError > > ;
409
+ ) -> BoxedFuture < ' a , Result < ( ) , AssetWriterError > > ;
399
410
/// Writes the asset meta `bytes` to the given `path`.
400
411
fn write_meta_bytes < ' a > (
401
412
& ' a self ,
402
413
path : & ' a Path ,
403
414
bytes : & ' a [ u8 ] ,
404
- ) -> BoxedFuture < Result < ( ) , AssetWriterError > > ;
415
+ ) -> BoxedFuture < ' a , Result < ( ) , AssetWriterError > > ;
405
416
}
406
417
407
418
impl < T : AssetWriter > ErasedAssetWriter for T {
408
- fn write < ' a > ( & ' a self , path : & ' a Path ) -> BoxedFuture < Result < Box < Writer > , AssetWriterError > > {
419
+ fn write < ' a > (
420
+ & ' a self ,
421
+ path : & ' a Path ,
422
+ ) -> BoxedFuture < ' a , Result < Box < Writer > , AssetWriterError > > {
409
423
Box :: pin ( Self :: write ( self , path) )
410
424
}
411
425
fn write_meta < ' a > (
412
426
& ' a self ,
413
427
path : & ' a Path ,
414
- ) -> BoxedFuture < Result < Box < Writer > , AssetWriterError > > {
428
+ ) -> BoxedFuture < ' a , Result < Box < Writer > , AssetWriterError > > {
415
429
Box :: pin ( Self :: write_meta ( self , path) )
416
430
}
417
- fn remove < ' a > ( & ' a self , path : & ' a Path ) -> BoxedFuture < Result < ( ) , AssetWriterError > > {
431
+ fn remove < ' a > ( & ' a self , path : & ' a Path ) -> BoxedFuture < ' a , Result < ( ) , AssetWriterError > > {
418
432
Box :: pin ( Self :: remove ( self , path) )
419
433
}
420
- fn remove_meta < ' a > ( & ' a self , path : & ' a Path ) -> BoxedFuture < Result < ( ) , AssetWriterError > > {
434
+ fn remove_meta < ' a > ( & ' a self , path : & ' a Path ) -> BoxedFuture < ' a , Result < ( ) , AssetWriterError > > {
421
435
Box :: pin ( Self :: remove_meta ( self , path) )
422
436
}
423
437
fn rename < ' a > (
424
438
& ' a self ,
425
439
old_path : & ' a Path ,
426
440
new_path : & ' a Path ,
427
- ) -> BoxedFuture < Result < ( ) , AssetWriterError > > {
441
+ ) -> BoxedFuture < ' a , Result < ( ) , AssetWriterError > > {
428
442
Box :: pin ( Self :: rename ( self , old_path, new_path) )
429
443
}
430
444
fn rename_meta < ' a > (
431
445
& ' a self ,
432
446
old_path : & ' a Path ,
433
447
new_path : & ' a Path ,
434
- ) -> BoxedFuture < Result < ( ) , AssetWriterError > > {
448
+ ) -> BoxedFuture < ' a , Result < ( ) , AssetWriterError > > {
435
449
Box :: pin ( Self :: rename_meta ( self , old_path, new_path) )
436
450
}
437
- fn remove_directory < ' a > ( & ' a self , path : & ' a Path ) -> BoxedFuture < Result < ( ) , AssetWriterError > > {
451
+ fn remove_directory < ' a > (
452
+ & ' a self ,
453
+ path : & ' a Path ,
454
+ ) -> BoxedFuture < ' a , Result < ( ) , AssetWriterError > > {
438
455
Box :: pin ( Self :: remove_directory ( self , path) )
439
456
}
440
457
fn remove_empty_directory < ' a > (
441
458
& ' a self ,
442
459
path : & ' a Path ,
443
- ) -> BoxedFuture < Result < ( ) , AssetWriterError > > {
460
+ ) -> BoxedFuture < ' a , Result < ( ) , AssetWriterError > > {
444
461
Box :: pin ( Self :: remove_empty_directory ( self , path) )
445
462
}
446
463
fn remove_assets_in_directory < ' a > (
447
464
& ' a self ,
448
465
path : & ' a Path ,
449
- ) -> BoxedFuture < Result < ( ) , AssetWriterError > > {
466
+ ) -> BoxedFuture < ' a , Result < ( ) , AssetWriterError > > {
450
467
Box :: pin ( Self :: remove_assets_in_directory ( self , path) )
451
468
}
452
469
fn write_bytes < ' a > (
453
470
& ' a self ,
454
471
path : & ' a Path ,
455
472
bytes : & ' a [ u8 ] ,
456
- ) -> BoxedFuture < Result < ( ) , AssetWriterError > > {
473
+ ) -> BoxedFuture < ' a , Result < ( ) , AssetWriterError > > {
457
474
Box :: pin ( Self :: write_bytes ( self , path, bytes) )
458
475
}
459
476
fn write_meta_bytes < ' a > (
460
477
& ' a self ,
461
478
path : & ' a Path ,
462
479
bytes : & ' a [ u8 ] ,
463
- ) -> BoxedFuture < Result < ( ) , AssetWriterError > > {
480
+ ) -> BoxedFuture < ' a , Result < ( ) , AssetWriterError > > {
464
481
Box :: pin ( Self :: write_meta_bytes ( self , path, bytes) )
465
482
}
466
483
}
0 commit comments