Skip to main content

async_flow/model/
outputs.rs

1// This is free and unencumbered software released into the public domain.
2
3use core::{marker::PhantomData, ops::Bound};
4
5/// A one-shot output port of type `T`.
6///
7/// Note that `Output` doesn't implement `Copy`, whereas `Input` does.
8pub type Output<T> = Outputs<T, 1, 0>;
9
10/// An output port of type `T`.
11///
12/// Note that `Outputs` doesn't implement `Copy`, whereas `Inputs` does.
13#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
14pub struct Outputs<T, const MAX: isize = -1, const MIN: isize = 0>(PhantomData<T>);
15
16impl<T, const MAX: isize, const MIN: isize> Default for Outputs<T, MAX, MIN> {
17    fn default() -> Self {
18        Self(PhantomData)
19    }
20}
21
22impl<T, const MAX: isize, const MIN: isize> Outputs<T, MAX, MIN> {
23    /// Returns the cardinality of this connection.
24    pub fn cardinality() -> (Bound<usize>, Bound<usize>) {
25        assert!(MIN >= 0);
26        assert!(MAX >= -1);
27        use Bound::*;
28        match (MIN, MAX) {
29            (min, -1) => (Included(min as _), Unbounded),
30            (min, max) => (Included(min as _), Included(max as _)),
31        }
32    }
33}