fdf_core/
lib.rs

1// Copyright 2025 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//! Bindings for the core of the fuchsia driver framework C API
6#![deny(unsafe_op_in_unsafe_fn, missing_docs)]
7
8pub mod dispatcher;
9pub mod handle;
10pub mod shutdown_observer;
11
12/// Gets the inner pointer of a dispatcher ref
13pub fn dispatcher_ptr<'a>(
14    dispatcher: &'a dispatcher::DispatcherRef<'a>,
15) -> &'a core::ptr::NonNull<fdf_sys::fdf_dispatcher_t> {
16    &dispatcher.0
17}
18
19/// Overrides the current dispatcher used by [`dispatcher::CurrentDispatcher::on_dispatcher`] while
20/// the callback is being called.
21pub fn override_current_dispatcher<R>(
22    dispatcher: dispatcher::DispatcherRef<'_>,
23    f: impl FnOnce() -> R,
24) -> R {
25    dispatcher::OVERRIDE_DISPATCHER.with(|global| {
26        let previous = global.replace(Some(dispatcher.0));
27        let res = f();
28        global.replace(previous);
29        res
30    })
31}