Skip to contentSkip to conversation

rust: types: add common init-helper functions for `Opaque`

PATCH Superseded [email protected] 1 participant 1 message Mar 31, 2023

Subsystems (2)

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 13/15 rust: types: add common init-helper functions for `Opaque`

From: Benno Lossin <[email protected]>

Add helper functions to more easily initialize Opaque<T> via FFI and rust raw initializer functions.
These functions take a function pointer to the FFI/raw initialization function and take between 0-4 other arguments. It then returns an initializer that uses the FFI/raw initialization function along with the given arguments to initialize an Opaque<T>.

---
 rust/kernel/init.rs  |  9 +++++++++
 rust/kernel/types.rs | 47 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+)
rust/kernel/init.rs +9 -0
index fef14c3c0642..7b452e458391 100644
@@ -177,6 +177,14 @@
 //! }
 //! ```
 //!
+//! For the special case where initializing a field is a single FFI-function call that cannot fail,
+//! there exist helper functions [`Opaque::ffi_init`]. These functions initialize a single
+//! [`Opaque`] field by just delegating to the FFI-function. You can use these in combination with
+//! [`pin_init!`].
+//!
+//! For more information on how to use [`pin_init_from_closure()`], take a look at the uses inside
+//! the `kernel` crate. The [`sync`] module is a good starting point.
+//!
 //! [`sync`]: kernel::sync
 //! [pinning]: https://doc.rust-lang.org/std/pin/index.html
 //! [structurally pinned fields]:
@@ -187,6 +195,7 @@
 //! [`impl PinInit<T, E>`]: PinInit
 //! [`impl Init<T, E>`]: Init
 //! [`Opaque`]: kernel::types::Opaque
+//! [`Opaque::ffi_init`]: kernel::types::Opaque::ffi_init
 //! [`pin_data`]: ::macros::pin_data
 
 use crate::{
rust/kernel/types.rs +47 -0

59 lines not on this page · raw message

--
2.39.2