Skip to main content

async_flow/model/
inputs.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 input port of type `T`.
6///
7/// Note that `Input` implements `Copy`, whereas `Output` doesn't.
8pub type Input<T> = Inputs<T, 1, 0>;
9
10/// An input port of type `T`.
11///
12/// Note that `Inputs` implements `Copy`, whereas `Outputs` doesn't.
13#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
14pub struct Inputs<T, const MAX: isize = -1, const MIN: isize = 0>(PhantomData<T>);
15
16impl<T, const MAX: isize, const MIN: isize> Default for Inputs<T, MAX, MIN> {
17    fn default() -> Self {
18        Self(PhantomData)
19    }
20}
21
22impl<T, const MAX: isize, const MIN: isize> Inputs<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}