n0_future/lib.rs
1//! Re-exports of abstractions and implementations deemed useful and good by number 0 engineers.
2//!
3//! Read up more on our challenges with rust's async: <https://www.iroh.computer/blog/async-rust-challenges-in-iroh>
4//!
5//! This library also allows importing a single [`task`] and [`time`] module that'll work
6//! in `wasm*-*-unknown` targets, using `wasm_bindgen` and `wasm_bindgen_futures`, but mirroring
7//! the `tokio` API with only minor differences.
8
9#![deny(missing_docs, rustdoc::broken_intra_doc_links)]
10#![cfg_attr(not(test), deny(clippy::unwrap_used))]
11#![cfg_attr(n0_future_docsrs, feature(doc_auto_cfg))]
12
13pub mod task;
14pub mod time;
15
16// futures-* re-exports
17
18pub use futures_buffered::*;
19pub use futures_lite::{future, io, pin, ready, stream, Future, FutureExt, Stream, StreamExt};
20pub use futures_util::{future::Either, Sink, SinkExt, TryFutureExt, TryStreamExt};
21
22/// Implementation and types for splitting a `Stream + Sink`.
23/// See [`split::split`].
24pub mod split {
25 pub use futures_util::stream::{SplitSink, SplitStream};
26
27 use crate::{Sink, Stream};
28
29 /// Splits a `Stream + Sink` object into separate `Sink` and `Stream`
30 /// objects.
31 ///
32 /// This can be useful when you want to split ownership between tasks, or
33 /// allow direct interaction between the two objects (e.g. via
34 /// `Sink::send_all`).
35 pub fn split<S, SinkItem>(stream_sink: S) -> (SplitSink<S, SinkItem>, SplitStream<S>)
36 where
37 S: Stream + Sized + Sink<SinkItem>,
38 {
39 use futures_util::stream::StreamExt as _;
40 stream_sink.split()
41 }
42}
43
44/// Re-exports boxed versions of [`Future`] and [`Stream`] traits
45/// that are `Send` in non-wasm and `!Send` in wasm.
46///
47/// If you don't want this type of target-dependend `Send` and `!Send`,
48/// use [`stream::Boxed`]/[`stream::BoxedLocal`] and
49/// [`future::Boxed`]/[`future::BoxedLocal`].
50///
51/// [`Future`]: futures_lite::Future
52/// [`Stream`]: futures_lite::Stream
53/// [`stream::Boxed`]: crate::stream::Boxed
54/// [`stream::BoxedLocal`]: crate::stream::BoxedLocal
55/// [`future::Boxed`]: crate::future::Boxed
56/// [`future::BoxedLocal`]: crate::future::BoxedLocal
57pub mod boxed {
58 #[cfg(not(wasm_browser))]
59 pub use futures_lite::future::Boxed as BoxFuture;
60 #[cfg(wasm_browser)]
61 pub use futures_lite::future::BoxedLocal as BoxFuture;
62
63 #[cfg(not(wasm_browser))]
64 pub use futures_lite::stream::Boxed as BoxStream;
65 #[cfg(wasm_browser)]
66 pub use futures_lite::stream::BoxedLocal as BoxStream;
67}