mod server;
#[doc(inline)]
pub use server::ServerRuntime;
use std::any::Any;
use async_trait::async_trait;
use puniyu_adapter_types::{AdapterInfo, SendMsgType};
use puniyu_contact::ContactType;
use puniyu_error::Result;
use puniyu_message::Message;
pub trait Runtime: Any + Send + Sync {}
impl<T> Runtime for T where T: Any + Send + Sync {}
impl dyn Runtime {
pub fn as_any(&self) -> &dyn Any {
self
}
pub fn downcast_ref<T: Any>(&self) -> Option<&T> {
self.as_any().downcast_ref::<T>()
}
}
pub trait AdapterProvider: Send + Sync {
fn adapter_info(&self) -> &AdapterInfo;
}
pub trait AdapterRuntime: Runtime + AdapterProvider + SendMessage {}
impl<T> AdapterRuntime for T where T: Runtime + AdapterProvider + SendMessage {}
#[async_trait]
pub trait SendMessage: Send + Sync {
async fn send_message(
&self,
contact: &ContactType<'_>,
message: &Message,
) -> Result<SendMsgType>;
}