* [PATCH] rust: vec: impl Default for Vec with any allocator
@ 2025-06-10 10:31 Alice Ryhl
2025-06-10 11:04 ` Benno Lossin
2025-06-11 17:31 ` Danilo Krummrich
0 siblings, 2 replies; 3+ messages in thread
From: Alice Ryhl @ 2025-06-10 10:31 UTC (permalink / raw)
To: Danilo Krummrich, Miguel Ojeda; +Cc: rust-for-linux, linux-kernel, Alice Ryhl
The implementation of Default is restricted to only work with kmalloc
vectors for no good reason. This means I have to use
mem::replace(&mut my_vec, KVVec::new())
in Rust Binder instead of `mem::take(&mut my_vec)`. Thus, expand the
impl of Default to work with any allocator including kvmalloc.
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
---
rust/kernel/alloc/kvec.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/rust/kernel/alloc/kvec.rs b/rust/kernel/alloc/kvec.rs
index 1a0dd852a468ccda6ea1b521bc1e7dbc8d7fc79c..606616fc0e592f87264bf905c88ef44e19739c0e 100644
--- a/rust/kernel/alloc/kvec.rs
+++ b/rust/kernel/alloc/kvec.rs
@@ -851,7 +851,7 @@ fn drop(&mut self) {
}
}
-impl<T> Default for KVec<T> {
+impl<T, A: Allocator> Default for Vec<T, A> {
#[inline]
fn default() -> Self {
Self::new()
---
base-commit: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494
change-id: 20250610-vec-default-4b0c54aadebc
Best regards,
--
Alice Ryhl <aliceryhl@google.com>
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] rust: vec: impl Default for Vec with any allocator
2025-06-10 10:31 [PATCH] rust: vec: impl Default for Vec with any allocator Alice Ryhl
@ 2025-06-10 11:04 ` Benno Lossin
2025-06-11 17:31 ` Danilo Krummrich
1 sibling, 0 replies; 3+ messages in thread
From: Benno Lossin @ 2025-06-10 11:04 UTC (permalink / raw)
To: Alice Ryhl, Danilo Krummrich, Miguel Ojeda; +Cc: rust-for-linux, linux-kernel
On Tue Jun 10, 2025 at 12:31 PM CEST, Alice Ryhl wrote:
> The implementation of Default is restricted to only work with kmalloc
> vectors for no good reason. This means I have to use
>
> mem::replace(&mut my_vec, KVVec::new())
>
> in Rust Binder instead of `mem::take(&mut my_vec)`. Thus, expand the
> impl of Default to work with any allocator including kvmalloc.
>
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Benno Lossin <lossin@kernel.org>
---
Cheers,
Benno
> ---
> rust/kernel/alloc/kvec.rs | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] rust: vec: impl Default for Vec with any allocator
2025-06-10 10:31 [PATCH] rust: vec: impl Default for Vec with any allocator Alice Ryhl
2025-06-10 11:04 ` Benno Lossin
@ 2025-06-11 17:31 ` Danilo Krummrich
1 sibling, 0 replies; 3+ messages in thread
From: Danilo Krummrich @ 2025-06-11 17:31 UTC (permalink / raw)
To: Alice Ryhl; +Cc: Miguel Ojeda, rust-for-linux, linux-kernel
On 6/10/25 12:31 PM, Alice Ryhl wrote:
> The implementation of Default is restricted to only work with kmalloc
> vectors for no good reason. This means I have to use
>
> mem::replace(&mut my_vec, KVVec::new())
>
> in Rust Binder instead of `mem::take(&mut my_vec)`. Thus, expand the
> impl of Default to work with any allocator including kvmalloc.
Applied to alloc-next, thanks!
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-06-11 17:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-10 10:31 [PATCH] rust: vec: impl Default for Vec with any allocator Alice Ryhl
2025-06-10 11:04 ` Benno Lossin
2025-06-11 17:31 ` Danilo Krummrich
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).