Skip to content

Commit 596049a

Browse files
tamirdjannau
authored andcommitted
rust: xarray: use the prelude
Using the prelude is customary in the kernel crate. Signed-off-by: Tamir Duberstein <tamird@gmail.com>
1 parent 149ba7f commit 596049a

1 file changed

Lines changed: 20 additions & 15 deletions

File tree

rust/kernel/xarray.rs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@
55
//! C header: [`include/linux/xarray.h`](srctree/include/linux/xarray.h)
66
77
use crate::{
8-
alloc, bindings, build_assert,
9-
error::{Error, Result},
10-
ffi::c_void,
8+
alloc,
9+
prelude::*,
1110
types::{ForeignOwnable, NotThreadSafe, Opaque},
1211
};
13-
use core::{iter, marker::PhantomData, pin::Pin, ptr::NonNull};
14-
use pin_init::{pin_data, pin_init, pinned_drop, PinInit};
12+
use core::{iter, marker::PhantomData, mem, ptr::NonNull};
1513

1614
/// An array which efficiently maps sparse integer indices to owned objects.
1715
///
18-
/// This is similar to a [`crate::alloc::kvec::Vec<Option<T>>`], but more efficient when there are
16+
/// This is similar to a [`Vec<Option<T>>`], but more efficient when there are
1917
/// holes in the index space, and can be efficiently grown.
2018
///
2119
/// # Invariants
@@ -105,16 +103,23 @@ impl<T: ForeignOwnable> XArray<T> {
105103
fn iter(&self) -> impl Iterator<Item = NonNull<c_void>> + '_ {
106104
let mut index = 0;
107105

108-
// SAFETY: `self.xa` is always valid by the type invariant.
109-
iter::once(unsafe {
110-
bindings::xa_find(self.xa.get(), &mut index, usize::MAX, bindings::XA_PRESENT)
111-
})
112-
.chain(iter::from_fn(move || {
106+
core::iter::Iterator::chain(
113107
// SAFETY: `self.xa` is always valid by the type invariant.
114-
Some(unsafe {
115-
bindings::xa_find_after(self.xa.get(), &mut index, usize::MAX, bindings::XA_PRESENT)
116-
})
117-
}))
108+
iter::once(unsafe {
109+
bindings::xa_find(self.xa.get(), &mut index, usize::MAX, bindings::XA_PRESENT)
110+
}),
111+
iter::from_fn(move || {
112+
// SAFETY: `self.xa` is always valid by the type invariant.
113+
Some(unsafe {
114+
bindings::xa_find_after(
115+
self.xa.get(),
116+
&mut index,
117+
usize::MAX,
118+
bindings::XA_PRESENT,
119+
)
120+
})
121+
}),
122+
)
118123
.map_while(|ptr| NonNull::new(ptr.cast()))
119124
}
120125

0 commit comments

Comments
 (0)