#![forbid(unsafe_code)]
#![deny(missing_docs)]
#[doc(hidden)]
pub use choices_derive::*;
pub mod bytes {
pub use bytes::*;
}
pub mod warp {
pub use warp::*;
}
#[cfg(feature = "json")]
pub mod serde_json {
pub use serde_json::*;
}
#[doc(hidden)]
pub use async_trait::*;
pub mod error;
pub use crate::error::{ChoicesError, ChoicesResult};
pub mod serde;
pub use crate::serde::{ChoicesInput, ChoicesOutput};
use std::net::SocketAddr;
use std::sync::{Arc, Mutex, RwLock};
#[self::async_trait]
pub trait Choices {
async fn run<T: Into<SocketAddr> + Send>(&'static self, addr: T);
#[doc(hidden)]
async fn run_mutable<T: Into<SocketAddr> + Send>(_: Arc<Mutex<Self>>, _: T) {
unimplemented!()
}
#[doc(hidden)]
async fn run_mutable_rw<T: Into<SocketAddr> + Send>(_: Arc<RwLock<Self>>, _: T)
where
Self: Sync,
{
unimplemented!()
}
}
#[self::async_trait]
impl<C: Choices + Send> Choices for Arc<Mutex<C>> {
async fn run<T: Into<SocketAddr> + Send>(&'static self, addr: T) {
C::run_mutable(self.clone(), addr).await;
}
}
#[self::async_trait]
impl<C: Choices + Send + Sync> Choices for Arc<RwLock<C>> {
async fn run<T: Into<SocketAddr> + Send>(&'static self, addr: T) {
C::run_mutable_rw(self.clone(), addr).await;
}
}