linera_views/future_sync_ext.rs
1// Copyright (c) Zefchain Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use std::{future::Future, pin::Pin};
5
6use sync_wrapper::SyncFuture;
7
8/// An extension trait to box futures and make them `Sync`.
9pub trait FutureSyncExt: Future + Sized {
10 /// Wrap the future so that it implements `Sync`
11 fn make_sync(self) -> SyncFuture<Self> {
12 SyncFuture::new(self)
13 }
14
15 /// Box the future without losing `Sync`ness
16 fn boxed_sync(self) -> Pin<Box<SyncFuture<Self>>> {
17 Box::pin(self.make_sync())
18 }
19}
20
21impl<F: Future> FutureSyncExt for F {}