mod client;
mod entities;
mod error;
pub use client::InnerClient;
pub use entities::activity;
pub use entities::packet;
pub use error::{BadResponseError, Error};
pub type Result<T> = std::result::Result<T, Error>;
use client::CallbackFn;
use packet::Packet;
use std::sync::Arc;
pub trait ClientType {}
impl ClientType for InnerClient {}
impl ClientType for Arc<InnerClient> {}
pub struct Client<T: ClientType>(T);
impl Client<InnerClient> {
pub fn new_simple(client_id: impl Into<String>) -> Self {
Self(InnerClient::new(client_id))
}
pub fn connect_and_wait(&self) -> Result<Packet> {
self.0.connect_and_wait(None)
}
pub fn send_and_wait(&self, packet: Packet) -> Result<Packet> {
self.0.send_and_wait(packet)
}
pub fn disconnect(&self) -> Result<()> {
self.0.disconnect()
}
}
impl Client<Arc<InnerClient>> {
pub fn new(client_id: impl Into<String>) -> Self {
Self(Arc::new(InnerClient::new(client_id)))
}
pub fn set_workers(&self, num_threads: usize) {
self.0.set_workers(num_threads)
}
pub fn connect(&self) -> Result<()> {
self.0.connect(Arc::clone(&self.0))
}
pub fn connect_and_wait(&self) -> Result<Packet> {
let client = Arc::clone(&self.0);
self.0.connect_and_wait(Some(client))
}
pub fn send(&self, packet: Packet) -> Result<()> {
self.0.send(packet)
}
pub fn send_and_wait(&self, packet: Packet) -> Result<Packet> {
self.0.send_and_wait(packet)
}
pub fn disconnect(&self) -> Result<()> {
self.0.disconnect()
}
pub fn on(&self, id: impl Into<String>, callback: impl CallbackFn) {
self.0.on(id, callback)
}
pub fn once(&self, id: impl Into<String>, callback: impl CallbackFn) {
self.0.once(id, callback)
}
}