Skip to main content

futures_bounded/
lib.rs

1mod delay;
2mod futures_map;
3mod futures_set;
4mod futures_tuple_set;
5mod stream_map;
6mod stream_set;
7
8pub use delay::Delay;
9pub use futures_map::FuturesMap;
10pub use futures_set::FuturesSet;
11pub use futures_tuple_set::FuturesTupleSet;
12pub use stream_map::StreamMap;
13pub use stream_set::StreamSet;
14
15use std::any::Any;
16use std::fmt;
17use std::fmt::Formatter;
18use std::pin::Pin;
19use std::time::Duration;
20
21/// A future failed to complete within the given timeout.
22#[derive(Debug)]
23pub struct Timeout {
24    limit: Duration,
25}
26
27impl Timeout {
28    fn new(duration: Duration) -> Self {
29        Self { limit: duration }
30    }
31}
32
33impl fmt::Display for Timeout {
34    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
35        write!(f, "future failed to complete within {:?}", self.limit)
36    }
37}
38
39/// Error of a future pushing
40#[derive(PartialEq)]
41pub enum PushError<T> {
42    /// The length of the set is equal to the capacity
43    BeyondCapacity(T),
44    /// The map already contained an item with this key.
45    ///
46    /// The old item is returned.
47    Replaced(T),
48}
49
50impl<T> fmt::Debug for PushError<T> {
51    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
52        match self {
53            Self::BeyondCapacity(_) => f.debug_tuple("BeyondCapacity").finish(),
54            Self::Replaced(_) => f.debug_tuple("Replaced").finish(),
55        }
56    }
57}
58
59impl std::error::Error for Timeout {}
60
61#[doc(hidden)]
62pub trait AnyStream: futures_util::Stream + Any + Send {}
63
64impl<T> AnyStream for T where T: futures_util::Stream + Any + Send {}
65
66type BoxStream<T> = Pin<Box<dyn AnyStream<Item = T> + Send>>;
67
68#[doc(hidden)]
69pub trait AnyFuture: std::future::Future + Any + Send {}
70
71impl<T> AnyFuture for T where T: std::future::Future + Any + Send {}
72
73type BoxFuture<T> = Pin<Box<dyn AnyFuture<Output = T> + Send>>;