swactor/src/error.rs
Zachery Aaron Shores-Chmielewski 98a2733173 feat: multithreaded runtime
Runtime is now configurable. Adds a tunable config for modifying the
size of pre-allocations for actor messaging channels, and for selecting
the number of threads the runtime will use.
2026-01-25 20:31:34 +07:00

31 lines
711 B
Rust

/// Simple, ergonomic, local `Error` type.
/// # Usage
/// ```
/// use swactor::Error;
///
/// fn foo_if_even(num: u64) -> Result<String, Error> {
/// if num % 2 == 0 {
/// return Ok("foo".into());
/// }
/// else {
/// return Err(Error::from("baz"));
/// }
/// }
/// ```
#[derive(Debug)]
pub struct Error(Box<dyn std::error::Error + Send + Sync + 'static>);
pub(crate) fn convert_err<E: std::fmt::Debug>(e: E) -> Error {
Error(format!("{e:?}").into())
}
impl<T: AsRef<str>> From<T> for Error {
fn from(value: T) -> Self {
convert_err(value.as_ref())
}
}
impl ToString for Error {
fn to_string(&self) -> String {
format!("{:?}", self.0)
}
}