@@ -28,12 +28,9 @@ use core::{
2828    pin:: Pin , 
2929    task:: { Context ,  Poll } , 
3030} ; 
31- use  futures_io:: { AsyncRead ,  AsyncSeek ,   AsyncWrite } ; 
31+ use  futures_io:: { AsyncRead ,  AsyncWrite } ; 
3232use  futures_lite:: { ready,  Stream } ; 
33- use  std:: { 
34-     io:: SeekFrom , 
35-     path:: { Path ,  PathBuf } , 
36- } ; 
33+ use  std:: path:: { Path ,  PathBuf } ; 
3734use  thiserror:: Error ; 
3835
3936/// Errors that occur while loading assets. 
@@ -83,13 +80,51 @@ pub const STACK_FUTURE_SIZE: usize = 10 * size_of::<&()>();
8380
8481pub  use  stackfuture:: StackFuture ; 
8582
83+ /// Asynchronously advances the cursor position by a specified number of bytes. 
84+ /// 
85+ /// This trait is a simplified version of the [`futures_io::AsyncSeek`] trait, providing 
86+ /// support exclusively for the [`futures_io::SeekFrom::Current`] variant. It allows for relative 
87+ /// seeking from the current cursor position. 
88+ pub  trait  AsyncSeekForward  { 
89+     /// Attempts to asynchronously seek forward by a specified number of bytes from the current cursor position. 
90+      /// 
91+      /// Seeking beyond the end of the stream is allowed and the behavior for this case is defined by the implementation. 
92+      /// The new position, relative to the beginning of the stream, should be returned upon successful completion 
93+      /// of the seek operation. 
94+      /// 
95+      /// If the seek operation completes successfully, 
96+      /// the new position relative to the beginning of the stream should be returned. 
97+      /// 
98+      /// # Implementation 
99+      /// 
100+      /// Implementations of this trait should handle [`Poll::Pending`] correctly, converting 
101+      /// [`std::io::ErrorKind::WouldBlock`] errors into [`Poll::Pending`] to indicate that the operation is not 
102+      /// yet complete and should be retried, and either internally retry or convert 
103+      /// [`std::io::ErrorKind::Interrupted`] into another error kind. 
104+      fn  poll_seek_forward ( 
105+         self :  Pin < & mut  Self > , 
106+         cx :  & mut  Context < ' _ > , 
107+         offset :  u64 , 
108+     )  -> Poll < futures_io:: Result < u64 > > ; 
109+ } 
110+ 
111+ impl < T :  ?Sized  + AsyncSeekForward  + Unpin >  AsyncSeekForward  for  Box < T >  { 
112+     fn  poll_seek_forward ( 
113+         mut  self :  Pin < & mut  Self > , 
114+         cx :  & mut  Context < ' _ > , 
115+         offset :  u64 , 
116+     )  -> Poll < futures_io:: Result < u64 > >  { 
117+         Pin :: new ( & mut  * * self ) . poll_seek_forward ( cx,  offset) 
118+     } 
119+ } 
120+ 
86121/// A type returned from [`AssetReader::read`], which is used to read the contents of a file 
87122/// (or virtual file) corresponding to an asset. 
88123/// 
89- /// This is essentially a trait alias for types implementing   [`AsyncRead`] and [`AsyncSeek `]. 
124+ /// This is essentially a trait alias for types implementing [`AsyncRead`] and [`AsyncSeekForward `]. 
90125/// The only reason a blanket implementation is not provided for applicable types is to allow 
91126/// implementors to override the provided implementation of [`Reader::read_to_end`]. 
92- pub  trait  Reader :  AsyncRead  + AsyncSeek  + Unpin  + Send  + Sync  { 
127+ pub  trait  Reader :  AsyncRead  + AsyncSeekForward  + Unpin  + Send  + Sync  { 
93128    /// Reads the entire contents of this reader and appends them to a vec. 
94129     /// 
95130     /// # Note for implementors 
@@ -559,32 +594,20 @@ impl AsyncRead for VecReader {
559594    } 
560595} 
561596
562- impl  AsyncSeek  for  VecReader  { 
563-     fn  poll_seek ( 
597+ impl  AsyncSeekForward  for  VecReader  { 
598+     fn  poll_seek_forward ( 
564599        mut  self :  Pin < & mut  Self > , 
565600        _cx :  & mut  Context < ' _ > , 
566-         pos :   SeekFrom , 
601+         offset :   u64 , 
567602    )  -> Poll < std:: io:: Result < u64 > >  { 
568-         let  result = match  pos { 
569-             SeekFrom :: Start ( offset)  => offset. try_into ( ) , 
570-             SeekFrom :: End ( offset)  => self . bytes . len ( ) . try_into ( ) . map ( |len :  i64 | len - offset) , 
571-             SeekFrom :: Current ( offset)  => self 
572-                 . bytes_read 
573-                 . try_into ( ) 
574-                 . map ( |bytes_read :  i64 | bytes_read + offset) , 
575-         } ; 
603+         let  result = self 
604+             . bytes_read 
605+             . try_into ( ) 
606+             . map ( |bytes_read :  u64 | bytes_read + offset) ; 
576607
577608        if  let  Ok ( new_pos)  = result { 
578-             if  new_pos < 0  { 
579-                 Poll :: Ready ( Err ( std:: io:: Error :: new ( 
580-                     std:: io:: ErrorKind :: InvalidInput , 
581-                     "seek position is out of range" , 
582-                 ) ) ) 
583-             }  else  { 
584-                 self . bytes_read  = new_pos as  _ ; 
585- 
586-                 Poll :: Ready ( Ok ( new_pos as  _ ) ) 
587-             } 
609+             self . bytes_read  = new_pos as  _ ; 
610+             Poll :: Ready ( Ok ( new_pos as  _ ) ) 
588611        }  else  { 
589612            Poll :: Ready ( Err ( std:: io:: Error :: new ( 
590613                std:: io:: ErrorKind :: InvalidInput , 
@@ -644,32 +667,21 @@ impl<'a> AsyncRead for SliceReader<'a> {
644667    } 
645668} 
646669
647- impl < ' a >  AsyncSeek  for  SliceReader < ' a >  { 
648-     fn  poll_seek ( 
670+ impl < ' a >  AsyncSeekForward  for  SliceReader < ' a >  { 
671+     fn  poll_seek_forward ( 
649672        mut  self :  Pin < & mut  Self > , 
650673        _cx :  & mut  Context < ' _ > , 
651-         pos :   SeekFrom , 
674+         offset :   u64 , 
652675    )  -> Poll < std:: io:: Result < u64 > >  { 
653-         let  result = match  pos { 
654-             SeekFrom :: Start ( offset)  => offset. try_into ( ) , 
655-             SeekFrom :: End ( offset)  => self . bytes . len ( ) . try_into ( ) . map ( |len :  i64 | len - offset) , 
656-             SeekFrom :: Current ( offset)  => self 
657-                 . bytes_read 
658-                 . try_into ( ) 
659-                 . map ( |bytes_read :  i64 | bytes_read + offset) , 
660-         } ; 
676+         let  result = self 
677+             . bytes_read 
678+             . try_into ( ) 
679+             . map ( |bytes_read :  u64 | bytes_read + offset) ; 
661680
662681        if  let  Ok ( new_pos)  = result { 
663-             if  new_pos < 0  { 
664-                 Poll :: Ready ( Err ( std:: io:: Error :: new ( 
665-                     std:: io:: ErrorKind :: InvalidInput , 
666-                     "seek position is out of range" , 
667-                 ) ) ) 
668-             }  else  { 
669-                 self . bytes_read  = new_pos as  _ ; 
682+             self . bytes_read  = new_pos as  _ ; 
670683
671-                 Poll :: Ready ( Ok ( new_pos as  _ ) ) 
672-             } 
684+             Poll :: Ready ( Ok ( new_pos as  _ ) ) 
673685        }  else  { 
674686            Poll :: Ready ( Err ( std:: io:: Error :: new ( 
675687                std:: io:: ErrorKind :: InvalidInput , 
0 commit comments