use std::sync::Arc;
use crate::{ActorRef, GateDecision, GateError, GateRequest};
pub trait Gate: Send + Sync + std::fmt::Debug {
fn check(&self, req: &GateRequest) -> Result<GateDecision, GateError>;
fn check_mailbox_read(
&self,
_req: &GateRequest,
_owner: &ActorRef,
) -> Result<GateDecision, GateError> {
Ok(GateDecision::deny("mailbox_read_not_granted"))
}
fn impl_name(&self) -> &'static str {
std::any::type_name::<Self>()
}
fn configuration_fingerprint(&self) -> Option<&str> {
None
}
}
pub type GateRef = Arc<dyn Gate>;
#[derive(Clone, Debug, Default)]
pub struct AllowAllGate;
impl Gate for AllowAllGate {
fn check(&self, _req: &GateRequest) -> Result<GateDecision, GateError> {
Ok(GateDecision::allow())
}
fn impl_name(&self) -> &'static str {
"AllowAllGate"
}
}