1#![allow(clippy::type_complexity)]
10#![warn(missing_docs)]
11#![warn(missing_copy_implementations, missing_debug_implementations)]
12#![warn(unused_qualifications, unused_results)]
13#![warn(future_incompatible)]
14#![warn(unused)]
15#![forbid(broken_intra_doc_links)]
17
18use dialectic::backend::{self, By, Choice, Mut, Ref, Val};
19use std::{convert::TryInto, future::Future, pin::Pin};
20
21pub type Chan<P> = dialectic::Chan<P, Sender, Receiver>;
34
35#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
37pub struct Receiver {
38 _private: (),
39}
40
41#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
43pub struct Sender {
44 _private: (),
45}
46
47pub fn channel() -> (Sender, Receiver) {
55 (Sender::default(), Receiver::default())
56}
57
58#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
62pub struct Error {
63 _private: (),
64}
65
66impl std::fmt::Display for Error {
67 fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
68 Ok(())
69 }
70}
71
72impl std::error::Error for Error {}
73
74impl backend::Transmitter for Sender {
75 type Error = Error;
76
77 fn send_choice<'async_lifetime, const LENGTH: usize>(
78 &'async_lifetime mut self,
79 _choice: Choice<LENGTH>,
80 ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_lifetime>> {
81 Box::pin(async { Ok(()) })
82 }
83}
84
85impl backend::Transmit<(), Val> for Sender {
86 fn send<'a, 'async_lifetime>(
87 &'async_lifetime mut self,
88 _message: <() as By<'a, Val>>::Type,
89 ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_lifetime>>
90 where
91 (): By<'a, Val>,
92 'a: 'async_lifetime,
93 {
94 Box::pin(async { Ok(()) })
95 }
96}
97
98impl backend::Transmit<(), Ref> for Sender {
99 fn send<'a, 'async_lifetime>(
100 &'async_lifetime mut self,
101 _message: <() as By<'a, Ref>>::Type,
102 ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_lifetime>>
103 where
104 (): By<'a, Ref>,
105 'a: 'async_lifetime,
106 {
107 Box::pin(async { Ok(()) })
108 }
109}
110
111impl backend::Transmit<(), Mut> for Sender {
112 fn send<'a, 'async_lifetime>(
113 &'async_lifetime mut self,
114 _message: <() as By<'a, Mut>>::Type,
115 ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_lifetime>>
116 where
117 (): By<'a, Mut>,
118 'a: 'async_lifetime,
119 {
120 Box::pin(async { Ok(()) })
121 }
122}
123
124impl<const LENGTH: usize> backend::Transmit<Choice<LENGTH>> for Sender {
125 fn send<'a, 'async_lifetime>(
126 &'async_lifetime mut self,
127 _message: <Choice<LENGTH> as By<Val>>::Type,
128 ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_lifetime>>
129 where
130 'a: 'async_lifetime,
131 {
132 Box::pin(async { Ok(()) })
133 }
134}
135
136impl backend::Receiver for Receiver {
137 type Error = Error;
138
139 fn recv_choice<'async_lifetime, const LENGTH: usize>(
140 &'async_lifetime mut self,
141 ) -> Pin<Box<dyn Future<Output = Result<Choice<LENGTH>, Self::Error>> + Send + 'async_lifetime>>
142 {
143 Box::pin(async { 0.try_into().map_err(|_| Error { _private: () }) })
144 }
145}
146
147impl backend::Receive<()> for Receiver {
148 fn recv<'async_lifetime>(
149 &'async_lifetime mut self,
150 ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_lifetime>> {
151 Box::pin(async { Ok(()) })
152 }
153}
154
155impl<const LENGTH: usize> backend::Receive<Choice<LENGTH>> for Receiver {
156 fn recv<'async_lifetime>(
157 &'async_lifetime mut self,
158 ) -> Pin<Box<dyn Future<Output = Result<Choice<LENGTH>, Self::Error>> + Send + 'async_lifetime>>
159 {
160 Box::pin(async { 0.try_into().map_err(|_| Error { _private: () }) })
161 }
162}