zenoh_sync/
lib.rs

1//
2// Copyright (c) 2023 ZettaScale Technology
3//
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7// which is available at https://www.apache.org/licenses/LICENSE-2.0.
8//
9// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
10//
11// Contributors:
12//   ZettaScale Zenoh Team, <zenoh@zettascale.tech>
13//
14
15//! ⚠️ WARNING ⚠️
16//!
17//! This module is intended for Zenoh's internal use.
18//!
19//! [Click here for Zenoh's documentation](https://docs.rs/zenoh/latest/zenoh)
20use std::{
21    future::Future,
22    pin::Pin,
23    task::{Context, Poll},
24};
25
26use futures::FutureExt;
27
28pub mod event;
29pub use event::*;
30
31pub mod fifo_queue;
32pub use fifo_queue::*;
33
34pub mod lifo_queue;
35pub use lifo_queue::*;
36
37pub mod object_pool;
38pub use object_pool::*;
39
40pub mod mvar;
41pub use mvar::*;
42
43pub mod condition;
44pub use condition::*;
45
46pub mod signal;
47pub use signal::*;
48
49pub fn get_mut_unchecked<T>(arc: &mut std::sync::Arc<T>) -> &mut T {
50    unsafe { &mut (*(std::sync::Arc::as_ptr(arc) as *mut T)) }
51}
52
53/// An alias for `Pin<Box<dyn Future<Output = T> + Send>>`.
54#[must_use = "futures do nothing unless you `.await` or poll them"]
55pub struct PinBoxFuture<T>(Pin<Box<dyn Future<Output = T> + Send>>);
56
57impl<T> Future for PinBoxFuture<T> {
58    type Output = T;
59
60    #[inline]
61    fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
62        self.0.poll_unpin(cx)
63    }
64}
65
66#[inline]
67pub fn pinbox<T>(fut: impl Future<Output = T> + Send + 'static) -> PinBoxFuture<T> {
68    PinBoxFuture(Box::pin(fut))
69}