laravel_comments/
moderation.rs1use std::future::Future;
4use std::pin::Pin;
5use std::sync::Arc;
6
7use crate::Status;
8
9#[derive(Debug, Clone)]
11pub struct NewComment {
12 pub commentable_type: &'static str,
14 pub commentable_id: i64,
16 pub parent_id: Option<i64>,
18 pub author_id: Option<i64>,
20 pub guest_email: Option<String>,
22 pub body: String,
24}
25
26type RuleFuture = Pin<Box<dyn Future<Output = laravel::Result<Status>> + Send>>;
27
28#[derive(Clone)]
31pub(crate) struct ModerationRule(pub(crate) Option<Arc<dyn Fn(NewComment) -> RuleFuture + Send + Sync>>);
32
33impl ModerationRule {
34 pub(crate) fn new<F, Fut>(rule: F) -> Self
35 where
36 F: Fn(NewComment) -> Fut + Send + Sync + 'static,
37 Fut: Future<Output = laravel::Result<Status>> + Send + 'static,
38 {
39 Self(Some(Arc::new(move |comment| Box::pin(rule(comment)))))
40 }
41}