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
13mod maybe_future;
14
15pub mod task;
16pub mod time;
17
18// futures-* re-exports
19
20pub use futures_buffered::*;
21pub use futures_lite::{future, io, pin, ready, stream, Future, FutureExt, Stream, StreamExt};
22pub use futures_util::{future::Either, Sink, SinkExt, TryFutureExt, TryStreamExt};
23pub use maybe_future::MaybeFuture;
24
25/// Implementation and types for splitting a `Stream + Sink`.
26/// See [`split::split`].
27pub mod split {
28 pub use futures_util::stream::{SplitSink, SplitStream};
29
30 use crate::{Sink, Stream};
31
32 /// Splits a `Stream + Sink` object into separate `Sink` and `Stream`
33 /// objects.
34 ///
35 /// This can be useful when you want to split ownership between tasks, or
36 /// allow direct interaction between the two objects (e.g. via
37 /// `Sink::send_all`).
38 pub fn split<S, SinkItem>(stream_sink: S) -> (SplitSink<S, SinkItem>, SplitStream<S>)
39 where
40 S: Stream + Sized + Sink<SinkItem>,
41 {
42 use futures_util::stream::StreamExt as _;
43 stream_sink.split()
44 }
45}
46
47/// Re-exports boxed versions of [`Future`] and [`Stream`] traits
48/// that are `Send` in non-wasm and `!Send` in wasm.
49///
50/// If you don't want this type of target-dependend `Send` and `!Send`,
51/// use [`stream::Boxed`]/[`stream::BoxedLocal`] and
52/// [`future::Boxed`]/[`future::BoxedLocal`].
53///
54/// [`Future`]: futures_lite::Future
55/// [`Stream`]: futures_lite::Stream
56/// [`stream::Boxed`]: crate::stream::Boxed
57/// [`stream::BoxedLocal`]: crate::stream::BoxedLocal
58/// [`future::Boxed`]: crate::future::Boxed
59/// [`future::BoxedLocal`]: crate::future::BoxedLocal
60pub mod boxed {
61 #[cfg(not(wasm_browser))]
62 pub use futures_lite::future::Boxed as BoxFuture;
63 #[cfg(wasm_browser)]
64 pub use futures_lite::future::BoxedLocal as BoxFuture;
65 #[cfg(not(wasm_browser))]
66 pub use futures_lite::stream::Boxed as BoxStream;
67 #[cfg(wasm_browser)]
68 pub use futures_lite::stream::BoxedLocal as BoxStream;
69}