use std::{any::type_name, sync::Arc};
use tokio::sync::Mutex;
pub use uid_derive::UID;
pub mod actor;
#[cfg(feature = "clients")]
pub mod clients;
pub mod io;
pub use io::UniqueIdentifier;
pub use io::Update;
pub mod model;
#[doc(inline)]
pub use actor::{Actor, Initiator, Task, Terminator};
mod network;
pub(crate) use network::ActorOutputBuilder;
pub use network::Entry;
pub use network::{AddOuput, IntoInputs, IntoLogs, IntoLogsN};
#[derive(thiserror::Error, Debug)]
pub enum ActorError {
#[error("{msg} receiver disconnected")]
DropRecv {
msg: String,
source: flume::RecvError,
},
#[error("{msg} sender disconnected")]
DropSend {
msg: String,
source: flume::SendError<()>,
},
#[error("no new data produced")]
NoData,
#[error("no inputs defined")]
NoInputs,
#[error("no outputs defined")]
NoOutputs,
#[error("no client defined")]
NoClient,
#[error("output {0} dropped")]
Disconnected(String),
#[error("{0} has some inputs but inputs rate is zero")]
SomeInputsZeroRate(String),
#[error("{0} has no inputs but a positive inputs rate (May be this Actor should instead be an Initiator)")]
NoInputsPositiveRate(String),
#[error("{0} has some outputs but outputs rate is zero")]
SomeOutputsZeroRate(String),
#[error("{0} has no outputs but a positive outputs rate (May be this Actor should instead be a Terminator)")]
NoOutputsPositiveRate(String),
#[error("Orphan output in {0} actor")]
OrphanOutput(String),
}
pub type Result<R> = std::result::Result<R, ActorError>;
pub trait ArcMutex {
fn into_arcx(self) -> Arc<Mutex<Self>>
where
Self: Sized,
{
Arc::new(Mutex::new(self))
}
}
impl<C: Update> ArcMutex for C {}
pub trait Who<T> {
fn who(&self) -> String {
type_name::<T>().to_string()
}
fn highlight(&self) -> String {
let me = <Self as Who<T>>::who(&self);
paris::formatter::colorize_string(format!("<italic><on-bright-cyan>{}</>", me))
}
fn lite(&self) -> String {
let me = <Self as Who<T>>::who(&self);
paris::formatter::colorize_string(format!("<italic><bright-cyan>{}</>", me))
}
}
use log::{info, warn};
pub(crate) fn print_info<S: Into<String>>(msg: S, e: Option<&dyn std::error::Error>) {
if let Some(e) = e {
let mut msg: Vec<String> = vec![msg.into()];
msg.push(format!("{}", e));
let mut current = e.source();
while let Some(cause) = current {
msg.push(format!("{}", cause));
current = cause.source();
}
warn!("{}", msg.join("\n .due to: "))
} else {
info!("{}", msg.into())
}
}
pub mod macros;
pub mod prelude {
#[cfg(feature = "clients")]
pub use super::clients::{
Integrator, Logging, OneSignal, Sampler, Signal, Signals, Source, Tick, Timer, Void,
};
pub use super::{
model::Model, Actor, AddOuput, ArcMutex, Initiator, IntoInputs, IntoLogs, IntoLogsN, Task,
Terminator, UID,
};
pub use crate::model;
pub use vec_box::vec_box;
}