Skip to contentSkip to conversation

rust: prelude: add `zerocopy{,_derive}::IntoBytes`

PATCH Applied Gary Guo 2 participants 2 messages Jun 11 – Jun 16 Rust

lore
Share & tools
lore

Gary Guo

author
#0 lore raw

PATCH 1/1 rust: prelude: add `zerocopy{,_derive}::IntoBytes`

From: Gary Guo <[email protected]>

In order to easily use IntoBytes, add it to the prelude.

This adds both the trait (zerocopy::IntoBytes) as well as the derive macro (zerocopy_derive::IntoBytes).

---
This is wanted because I want to convert the upcoming I/O projection series to use zerocopy traits rather than keep using transmute module.

It is most helpful for derives in doc tests; I do not want to explicitly use #[derive(zerocopy_derive::IntoBytes)] in the doc tests.

---
 rust/kernel/prelude.rs | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
rust/kernel/prelude.rs +8 -2
index ca260cc3937a..a97cb0af5d02 100644
@@ -61,10 +61,16 @@
 };
 
 #[doc(no_inline)]
-pub use zerocopy::FromBytes;
+pub use zerocopy::{
+    FromBytes,
+    IntoBytes, //
+};
 
 #[doc(no_inline)]
-pub use zerocopy_derive::FromBytes;
+pub use zerocopy_derive::{
+    FromBytes,
+    IntoBytes, //
+};
 
 #[doc(no_inline)]
 pub use super::{

base-commit: 98cc68794c003bc76fc9da2e8a075e947eee5921

Signature · 1 line
2.54.0
Applied
#1 lore raw
Quoted 7 lines · Gary Guo

In order to easily use IntoBytes, add it to the prelude.

This adds both the trait (zerocopy::IntoBytes) as well as the derive macro (zerocopy_derive::IntoBytes).

Applied to rust-next (for a potential second PR to Linus) -- thanks!

[ This patch will simplify using the feature in several trees next cycle.

Gary writes:

This is wanted because I want to convert the upcoming I/O projection series to use zerocopy traits rather than keep using transmute module.

It is most helpful for derives in doc tests; I do not want to explicitly use #[derive(zerocopy_derive::IntoBytes)] in the doc tests.

For reference, the upcoming I/O projection series is at:

https://lore.kernel.org/rust-for-linux/[email protected]/

- Miguel ]

There should no build errors from what I tested, but if there are, we should discover them during this week or so. Worst case, we drop the trait and keep the derive as discussed.

Cheers,
Miguel