Skip to contentSkip to conversation

rust: vec: impl Default for Vec with any allocator

PATCH Applied Alice Ryhl 3 participants 3 messages Jun 10, 2025 – Jun 11, 2025

Subsystems (2)
lore
Share & tools
lore

Alice Ryhl

author maintainer
#0 lore raw

PATCH 1/1 rust: vec: impl Default for Vec with any allocator

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.

---
 rust/kernel/alloc/kvec.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
rust/kernel/alloc/kvec.rs +1 -1
index 1a0dd852a468ccda6ea1b521bc1e7dbc8d7fc79c..606616fc0e592f87264bf905c88ef44e19739c0e 100644
@@ -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,

Signature · 1 line
Alice Ryhl <[email protected]>
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · 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.

---
Cheers,
Benno

Quoted 3 lines
---
 rust/kernel/alloc/kvec.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
maintainer Applied
#2 lore raw
In reply to Alice Ryhl
Quoted 7 lines · 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.

Applied to alloc-next, thanks!