1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//! Opaque thin-pointer handle for passing boxed futures through C ABI.
use Box;
use ;
/// Opaque handle wrapping a boxed future for passing through C ABI.
///
/// A trait-object future like [`BoxFuture`](futures::future::BoxFuture)
/// is a fat pointer (data + vtable) that cannot be passed as a single
/// `*mut void` through C ABI. `HostHandle` wraps it in an outer `Box`,
/// producing a thin pointer suitable for opaque-handle FFI patterns.
///
/// # Type parameter
///
/// `F` is the future type — typically [`BoxFuture<'static, T>`] for
/// `Send` futures or [`LocalBoxFuture<'static, T>`] for `!Send` futures.
/// This keeps a single type for both cases; the `Send`-ness is carried
/// by `F` itself.
///
/// [`BoxFuture<'static, T>`]: futures::future::BoxFuture
/// [`LocalBoxFuture<'static, T>`]: futures::future::LocalBoxFuture
///
/// # Usage
///
/// Bridge authors create a handle from a boxed future, convert it to a
/// raw pointer for the C ABI, and later reconstruct it to poll or free:
///
/// ```rust,ignore
/// // In an `extern "C"` function:
/// let fut: BoxFuture<'static, u64> = Sendable::from_future(async { 42 });
/// let handle = HostHandle::new(fut);
/// let ptr = Box::into_raw(Box::new(handle)); // thin *mut for C
///
/// // Later, to poll:
/// let handle = &mut *ptr;
/// let result = handle.poll_once();
///
/// // To free:
/// drop(Box::from_raw(ptr));
/// ```
///
/// For handles that need additional per-future state (e.g., a stashed
/// effect tag), see [`EffectHandle`](crate::effect_handle::EffectHandle).
///
/// # Why not a [`LocalBoxFuture`](futures::future::LocalBoxFuture) variant?
///
/// There is no separate `LocalHostHandle` — just use
/// `HostHandle<LocalBoxFuture<'static, T>>`. The `Send` vs `!Send`
/// distinction is carried by the type parameter.
;