@@ -1033,13 +1033,79 @@ impl ReadDirAllocation {
1033
1033
}
1034
1034
}
1035
1035
1036
+ #[ derive( Debug , Clone , Copy , Eq , PartialEq , Ord , PartialOrd , Hash ) ]
1037
+ pub struct DirIterationTell {
1038
+ tell_result : u32 ,
1039
+ }
1040
+
1036
1041
pub struct ReadDir < ' a , ' b , S : driver:: Storage > {
1037
1042
alloc : RefCell < & ' b mut ReadDirAllocation > ,
1038
1043
fs : & ' b Filesystem < ' a , S > ,
1039
1044
#[ cfg( feature = "dir-entry-path" ) ]
1040
1045
path : PathBuf ,
1041
1046
}
1042
1047
1048
+ impl < ' a , ' b , S : driver:: Storage > ReadDir < ' a , ' b , S > {
1049
+ /// Return the position of the directory
1050
+ ///
1051
+ /// The returned offset is only meant to be consumed by seek and may not make
1052
+ /// sense, but does indicate the current position in the directory iteration.
1053
+ ///
1054
+ /// Returns the position of the directory, which can be returned to using [`seek`](Self::seek).
1055
+ pub fn tell ( & self ) -> Result < DirIterationTell > {
1056
+ let value = unsafe {
1057
+ ll:: lfs_dir_tell (
1058
+ & mut self . fs . alloc . borrow_mut ( ) . state ,
1059
+ & mut self . alloc . borrow_mut ( ) . state ,
1060
+ )
1061
+ } ;
1062
+ if value < 0 {
1063
+ Err ( io:: result_from ( ( ) , value) . unwrap_err ( ) )
1064
+ } else {
1065
+ Ok ( DirIterationTell {
1066
+ tell_result : value as u32 ,
1067
+ } )
1068
+ }
1069
+ }
1070
+
1071
+ /// Change the position of the directory
1072
+ ///
1073
+ /// The new off must be a value previous returned from [`tell`](Self::tell) and specifies
1074
+ /// an absolute offset in the directory seek.
1075
+ pub fn seek ( & mut self , state : DirIterationTell ) -> Result < DirIterationTell > {
1076
+ let value = unsafe {
1077
+ ll:: lfs_dir_seek (
1078
+ & mut self . fs . alloc . borrow_mut ( ) . state ,
1079
+ & mut self . alloc . borrow_mut ( ) . state ,
1080
+ state. tell_result ,
1081
+ )
1082
+ } ;
1083
+ if value < 0 {
1084
+ Err ( io:: result_from ( ( ) , value) . unwrap_err ( ) )
1085
+ } else {
1086
+ Ok ( DirIterationTell {
1087
+ tell_result : value as u32 ,
1088
+ } )
1089
+ }
1090
+ }
1091
+
1092
+ /// Change the position of the directory to the beginning of the directory
1093
+ pub fn rewind ( & mut self ) -> Result < ( ) > {
1094
+ let res = unsafe {
1095
+ ll:: lfs_dir_rewind (
1096
+ & mut self . fs . alloc . borrow_mut ( ) . state ,
1097
+ & mut self . alloc . borrow_mut ( ) . state ,
1098
+ )
1099
+ } ;
1100
+
1101
+ if res < 0 {
1102
+ Err ( io:: result_from ( ( ) , res) . unwrap_err ( ) )
1103
+ } else {
1104
+ Ok ( ( ) )
1105
+ }
1106
+ }
1107
+ }
1108
+
1043
1109
impl < ' a , ' b , S : driver:: Storage > Iterator for ReadDir < ' a , ' b , S > {
1044
1110
type Item = Result < DirEntry > ;
1045
1111
0 commit comments