@@ -1007,13 +1007,79 @@ impl ReadDirAllocation {
1007
1007
}
1008
1008
}
1009
1009
1010
+ #[ derive( Debug , Clone , Copy , Eq , PartialEq , Ord , PartialOrd , Hash ) ]
1011
+ pub struct DirIterationTell {
1012
+ tell_result : u32 ,
1013
+ }
1014
+
1010
1015
pub struct ReadDir < ' a , ' b , S : driver:: Storage > {
1011
1016
alloc : RefCell < & ' b mut ReadDirAllocation > ,
1012
1017
fs : & ' b Filesystem < ' a , S > ,
1013
1018
#[ cfg( feature = "dir-entry-path" ) ]
1014
1019
path : PathBuf ,
1015
1020
}
1016
1021
1022
+ impl < ' a , ' b , S : driver:: Storage > ReadDir < ' a , ' b , S > {
1023
+ /// Return the position of the directory
1024
+ ///
1025
+ /// The returned offset is only meant to be consumed by seek and may not make
1026
+ /// sense, but does indicate the current position in the directory iteration.
1027
+ ///
1028
+ /// Returns the position of the directory, which can be returned to using [`seek`](Self::seek).
1029
+ pub fn tell ( & self ) -> Result < DirIterationTell > {
1030
+ let value = unsafe {
1031
+ ll:: lfs_dir_tell (
1032
+ & mut self . fs . alloc . borrow_mut ( ) . state ,
1033
+ & mut self . alloc . borrow_mut ( ) . state ,
1034
+ )
1035
+ } ;
1036
+ if value < 0 {
1037
+ Err ( io:: result_from ( ( ) , value) . unwrap_err ( ) )
1038
+ } else {
1039
+ Ok ( DirIterationTell {
1040
+ tell_result : value as u32 ,
1041
+ } )
1042
+ }
1043
+ }
1044
+
1045
+ /// Change the position of the directory
1046
+ ///
1047
+ /// The new off must be a value previous returned from [`tell`](Self::tell) and specifies
1048
+ /// an absolute offset in the directory seek.
1049
+ pub fn seek ( & mut self , state : DirIterationTell ) -> Result < DirIterationTell > {
1050
+ let value = unsafe {
1051
+ ll:: lfs_dir_seek (
1052
+ & mut self . fs . alloc . borrow_mut ( ) . state ,
1053
+ & mut self . alloc . borrow_mut ( ) . state ,
1054
+ state. tell_result ,
1055
+ )
1056
+ } ;
1057
+ if value < 0 {
1058
+ Err ( io:: result_from ( ( ) , value) . unwrap_err ( ) )
1059
+ } else {
1060
+ Ok ( DirIterationTell {
1061
+ tell_result : value as u32 ,
1062
+ } )
1063
+ }
1064
+ }
1065
+
1066
+ /// Change the position of the directory to the beginning of the directory
1067
+ pub fn rewind ( & mut self ) -> Result < ( ) > {
1068
+ let res = unsafe {
1069
+ ll:: lfs_dir_rewind (
1070
+ & mut self . fs . alloc . borrow_mut ( ) . state ,
1071
+ & mut self . alloc . borrow_mut ( ) . state ,
1072
+ )
1073
+ } ;
1074
+
1075
+ if res < 0 {
1076
+ Err ( io:: result_from ( ( ) , res) . unwrap_err ( ) )
1077
+ } else {
1078
+ Ok ( ( ) )
1079
+ }
1080
+ }
1081
+ }
1082
+
1017
1083
impl < ' a , ' b , S : driver:: Storage > Iterator for ReadDir < ' a , ' b , S > {
1018
1084
type Item = Result < DirEntry > ;
1019
1085
0 commit comments