@@ -45,7 +45,8 @@ impl<'buf, Fd: AsFd> RawDir<'buf, Fd> {
45
45
/// let fd = openat(cwd(), ".", OFlags::RDONLY | OFlags::DIRECTORY, Mode::empty()).unwrap();
46
46
///
47
47
/// let mut buf = Vec::with_capacity(8192);
48
- /// for entry in RawDir::new(fd, buf.spare_capacity_mut()) {
48
+ /// let mut iter = RawDir::new(fd, buf.spare_capacity_mut());
49
+ /// while let Some(entry) = iter.next() {
49
50
/// let entry = entry.unwrap();
50
51
/// dbg!(&entry);
51
52
/// }
@@ -60,7 +61,8 @@ impl<'buf, Fd: AsFd> RawDir<'buf, Fd> {
60
61
/// let fd = openat(cwd(), ".", OFlags::RDONLY | OFlags::DIRECTORY, Mode::empty()).unwrap();
61
62
///
62
63
/// let mut buf = [MaybeUninit::uninit(); 2048];
63
- /// for entry in RawDir::new(fd, &mut buf) {
64
+ /// let mut iter = RawDir::new(fd, &mut buf);
65
+ /// while let Some(entry) = iter.next() {
64
66
/// let entry = entry.unwrap();
65
67
/// dbg!(&entry);
66
68
/// }
@@ -82,7 +84,8 @@ impl<'buf, Fd: AsFd> RawDir<'buf, Fd> {
82
84
/// let mut buf = Vec::with_capacity(8192);
83
85
/// 'read: loop {
84
86
/// 'resize: {
85
- /// for entry in RawDir::new(&fd, buf.spare_capacity_mut()) {
87
+ /// let mut iter = RawDir::new(&fd, buf.spare_capacity_mut());
88
+ /// while let Some(entry) = iter.next() {
86
89
/// let entry = match entry {
87
90
/// Err(Errno::INVAL) => break 'resize,
88
91
/// r => r.unwrap(),
@@ -162,11 +165,13 @@ impl<'a> RawDirEntry<'a> {
162
165
}
163
166
}
164
167
165
- impl < ' buf , Fd : AsFd > Iterator for RawDir < ' buf , Fd > {
166
- type Item = io:: Result < RawDirEntry < ' buf > > ;
167
-
168
+ impl < ' buf , Fd : AsFd > RawDir < ' buf , Fd > {
169
+ /// Identical to [Iterator::next] except that [Iterator::Item] borrows from self.
170
+ ///
171
+ /// Note: this interface will be broken to implement a stdlib iterator API with
172
+ /// GAT support once one becomes available.
168
173
#[ allow( unsafe_code) ]
169
- fn next ( & mut self ) -> Option < Self :: Item > {
174
+ pub fn next ( & mut self ) -> Option < io :: Result < RawDirEntry > > {
170
175
loop {
171
176
if self . offset < self . initialized {
172
177
let dirent_ptr = self . buf [ self . offset ..] . as_ptr ( ) ;
0 commit comments