rust: types: add common init-helper functions for `Opaque`
Subsystems (2)
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>.
Signed-off-by Benno Lossin <[email protected]>
Reviewed-by Alice Ryhl <[email protected]>
Reviewed-by Andreas Hindborg <[email protected]>
Cc Gary Guo <[email protected]>
--- rust/kernel/init.rs | 9 +++++++++ rust/kernel/types.rs | 47 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+)
rust/kernel/init.rs +9 -0
@@ -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