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 mod cache;
50pub use cache::*;
51
52pub fn get_mut_unchecked<T>(arc: &mut std::sync::Arc<T>) -> &mut T {
53    unsafe { &mut (*(std::sync::Arc::as_ptr(arc) as *mut T)) }
54}
55
56/// An alias for `Pin<Box<dyn Future<Output = T> + Send>>`.
57#[must_use = "futures do nothing unless you `.await` or poll them"]
58pub struct PinBoxFuture<T>(Pin<Box<dyn Future<Output = T> + Send>>);
59
60impl<T> Future for PinBoxFuture<T> {
61    type Output = T;
62
63    #[inline]
64    fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
65        self.0.poll_unpin(cx)
66    }
67}
68
69#[inline]
70pub fn pinbox<T>(fut: impl Future<Output = T> + Send + 'static) -> PinBoxFuture<T> {
71    PinBoxFuture(Box::pin(fut))
72}