fusio_core/maybe.rs
1use core::future::Future;
2
3#[cfg(not(feature = "no-send"))]
4pub unsafe trait MaybeSend: Send {
5 //! Considering lots of runtimes does not require [`std::marker::Send`] for
6 //! [`std::future::Future`] and [`futures_core::stream::Stream`], we provide a trait to
7 //! represent the future or stream that may not require [`std::marker::Send`]. Users could
8 //! switch the feature `no-send` at compile-time to disable the [`std::marker::Send`] bound
9 //! for [`std::future::Future`] and [`futures_core::stream::Stream`].
10 //!
11 //! # Safety
12 //! Do not implement it directly.
13}
14
15/// # Safety
16/// Do not implement it directly
17#[cfg(feature = "no-send")]
18pub unsafe trait MaybeSend {}
19
20#[cfg(not(feature = "no-send"))]
21unsafe impl<T: Send> MaybeSend for T {}
22#[cfg(feature = "no-send")]
23unsafe impl<T> MaybeSend for T {}
24
25#[cfg(not(feature = "no-send"))]
26pub unsafe trait MaybeSync: Sync {
27 //! Same as [`MaybeSend`], but for [`std::marker::Sync`].
28 //!
29 //! # Safety
30 //! Do not implement it directly.
31}
32
33#[cfg(feature = "no-send")]
34pub unsafe trait MaybeSync {
35 //! Same as [`MaybeSend`], but for [`std::marker::Sync`].
36 //!
37 //! # Safety
38 //! Do not implement it directly.
39}
40
41#[cfg(not(feature = "no-send"))]
42unsafe impl<T: Sync> MaybeSync for T {}
43#[cfg(feature = "no-send")]
44unsafe impl<T> MaybeSync for T {}
45
46#[cfg(not(feature = "completion-based"))]
47pub unsafe trait MaybeOwned {
48 //! A trait for determining whether the buffer is owned or borrowed.
49 //! Poll-based I/O operations require the buffer to be borrowed, while completion-based I/O
50 //! operations require the buffer to be owned. This trait provides a way to abstract over
51 //! the ownership of the buffer. Users could switch between poll-based and completion-based
52 //! I/O operations at compile-time by enabling or disabling the `completion-based` feature.
53 //!
54 //! # Safety
55 //! Do not implement this trait manually.
56}
57#[cfg(not(feature = "completion-based"))]
58unsafe impl<T> MaybeOwned for T {}
59
60#[cfg(feature = "completion-based")]
61pub unsafe trait MaybeOwned: 'static {}
62
63#[cfg(feature = "completion-based")]
64unsafe impl<T: 'static> MaybeOwned for T {}
65
66pub trait MaybeSendFuture: Future + MaybeSend {}
67
68impl<F> MaybeSendFuture for F where F: Future + MaybeSend {}