#![allow(clippy::type_complexity)]
#![warn(missing_docs)]
#![warn(missing_copy_implementations, missing_debug_implementations)]
#![warn(unused_qualifications, unused_results)]
#![warn(future_incompatible)]
#![warn(unused)]
#![forbid(broken_intra_doc_links)]
use dialectic::backend::{self, By, Choice, Mut, Ref, Val};
use std::{convert::TryInto, future::Future, pin::Pin};
pub type Chan<P> = dialectic::Chan<P, Sender, Receiver>;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
pub struct Receiver {
_private: (),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
pub struct Sender {
_private: (),
}
pub fn channel() -> (Sender, Receiver) {
(Sender::default(), Receiver::default())
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Error {
_private: (),
}
impl std::fmt::Display for Error {
fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Ok(())
}
}
impl std::error::Error for Error {}
impl backend::Transmitter for Sender {
type Error = Error;
fn send_choice<'async_lifetime, const LENGTH: usize>(
&'async_lifetime mut self,
_choice: Choice<LENGTH>,
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_lifetime>> {
Box::pin(async { Ok(()) })
}
}
impl backend::Transmit<(), Val> for Sender {
fn send<'a, 'async_lifetime>(
&'async_lifetime mut self,
_message: <() as By<'a, Val>>::Type,
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_lifetime>>
where
(): By<'a, Val>,
'a: 'async_lifetime,
{
Box::pin(async { Ok(()) })
}
}
impl backend::Transmit<(), Ref> for Sender {
fn send<'a, 'async_lifetime>(
&'async_lifetime mut self,
_message: <() as By<'a, Ref>>::Type,
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_lifetime>>
where
(): By<'a, Ref>,
'a: 'async_lifetime,
{
Box::pin(async { Ok(()) })
}
}
impl backend::Transmit<(), Mut> for Sender {
fn send<'a, 'async_lifetime>(
&'async_lifetime mut self,
_message: <() as By<'a, Mut>>::Type,
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_lifetime>>
where
(): By<'a, Mut>,
'a: 'async_lifetime,
{
Box::pin(async { Ok(()) })
}
}
impl<const LENGTH: usize> backend::Transmit<Choice<LENGTH>> for Sender {
fn send<'a, 'async_lifetime>(
&'async_lifetime mut self,
_message: <Choice<LENGTH> as By<Val>>::Type,
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_lifetime>>
where
'a: 'async_lifetime,
{
Box::pin(async { Ok(()) })
}
}
impl backend::Receiver for Receiver {
type Error = Error;
fn recv_choice<'async_lifetime, const LENGTH: usize>(
&'async_lifetime mut self,
) -> Pin<Box<dyn Future<Output = Result<Choice<LENGTH>, Self::Error>> + Send + 'async_lifetime>>
{
Box::pin(async { 0.try_into().map_err(|_| Error { _private: () }) })
}
}
impl backend::Receive<()> for Receiver {
fn recv<'async_lifetime>(
&'async_lifetime mut self,
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_lifetime>> {
Box::pin(async { Ok(()) })
}
}
impl<const LENGTH: usize> backend::Receive<Choice<LENGTH>> for Receiver {
fn recv<'async_lifetime>(
&'async_lifetime mut self,
) -> Pin<Box<dyn Future<Output = Result<Choice<LENGTH>, Self::Error>> + Send + 'async_lifetime>>
{
Box::pin(async { 0.try_into().map_err(|_| Error { _private: () }) })
}
}