use crate::error::Result;
use async_trait::async_trait;
use serde_json::Value;
use std::sync::Arc;
pub trait ActorContext: Send + Sync {
fn actor_json(&self) -> &Value;
}
pub struct JsonActorContext {
json: Value,
}
impl JsonActorContext {
#[must_use]
pub fn new(json: Value) -> Self {
Self { json }
}
}
impl ActorContext for JsonActorContext {
fn actor_json(&self) -> &Value {
&self.json
}
}
#[async_trait]
pub trait ActorFactory: Send + Sync {
fn build(&self, actor_json: &Value) -> Result<Arc<dyn ActorContext>>;
}
#[derive(Debug, Default, Clone, Copy)]
pub struct JsonActorFactory;
#[async_trait]
impl ActorFactory for JsonActorFactory {
fn build(&self, actor_json: &Value) -> Result<Arc<dyn ActorContext>> {
Ok(Arc::new(JsonActorContext::new(actor_json.clone())))
}
}