From d49c56368c0cc98cdf02ae21dd275eba92f1c333 Mon Sep 17 00:00:00 2001 From: Benno Lossin Date: Fri, 5 Sep 2025 19:12:06 +0200 Subject: rust: pin-init: rename `project` -> `project_this` in doctest The next commit makes the `#[pin_data]` attribute generate a `project` function that would collide with any existing ones. Signed-off-by: Benno Lossin --- rust/pin-init/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'rust/pin-init/src/lib.rs') diff --git a/rust/pin-init/src/lib.rs b/rust/pin-init/src/lib.rs index 62e013a5cc20..2d0d9fd12524 100644 --- a/rust/pin-init/src/lib.rs +++ b/rust/pin-init/src/lib.rs @@ -994,7 +994,7 @@ macro_rules! try_init { /// } /// /// impl Foo { -/// fn project(self: Pin<&mut Self>) -> Pin<&mut T> { +/// fn project_this(self: Pin<&mut Self>) -> Pin<&mut T> { /// assert_pinned!(Foo, elem, T, inline); /// /// // SAFETY: The field is structurally pinned. -- cgit v1.2.3 From 1fa516794fdd27b96cee77f8b12ac916b8b6a9a7 Mon Sep 17 00:00:00 2001 From: Benno Lossin Date: Fri, 5 Sep 2025 16:05:31 +0200 Subject: rust: pin-init: add code blocks to `[try_][pin_]init!` macros Allow writing `_: { /* any number of statements */ }` in initializers to run arbitrary code during initialization. try_init!(MyStruct { _: { if check_something() { return Err(MyError); } }, foo: Foo::new(val), _: { println!("successfully initialized `MyStruct`"); }, }) Tested-by: Alexandre Courbot Reviewed-by: Gary Guo Reviewed-by: Alice Ryhl Tested-by: Danilo Krummrich Reviewed-by: Danilo Krummrich Signed-off-by: Benno Lossin --- rust/pin-init/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'rust/pin-init/src/lib.rs') diff --git a/rust/pin-init/src/lib.rs b/rust/pin-init/src/lib.rs index 2d0d9fd12524..dd553212836e 100644 --- a/rust/pin-init/src/lib.rs +++ b/rust/pin-init/src/lib.rs @@ -740,6 +740,8 @@ macro_rules! stack_try_pin_init { /// As already mentioned in the examples above, inside of `pin_init!` a `struct` initializer with /// the following modifications is expected: /// - Fields that you want to initialize in-place have to use `<-` instead of `:`. +/// - You can use `_: { /* run any user-code here */ },` anywhere where you can place fields in +/// order to run arbitrary code. /// - In front of the initializer you can write `&this in` to have access to a [`NonNull`] /// pointer named `this` inside of the initializer. /// - Using struct update syntax one can place `..Zeroable::init_zeroed()` at the very end of the -- cgit v1.2.3