Skip to main content

zr/
pin_init.rs

1// Copyright 2026 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5/// A helper macro to initialize a pinned object in-place using a raw FFI constructor.
6///
7/// This generates a `PinInit` block that passes a type-cast pointer of the allocated
8/// slot to the FFI function, returning `Ok(())`.
9#[macro_export]
10macro_rules! pin_init_ffi {
11    ($ffi_fn:expr) => {
12        unsafe {
13            pin_init::pin_init_from_closure(|slot| {
14                let ptr = slot as *mut _ as *mut core::ffi::c_void;
15                $ffi_fn(ptr);
16                Ok(())
17            })
18        }
19    };
20}