laravel-comments 0.2.1

Comments for Laravel Rust models: threaded replies, moderation, reactions, and events, without N+1 queries.
Documentation
//! Who writes a comment: one of the application's users, or a guest.

/// The application's users model, as the author of comments.
///
/// ```no_run
/// # use laravel::model::model;
/// # #[model] pub struct User { pub id: i64 }
/// use laravel_comments::Commenter;
///
/// impl Commenter for User {
///     fn commenter_id(&self) -> i64 {
///         self.id
///     }
/// }
/// ```
pub trait Commenter {
    /// The user's key, which the comment's `author_id` stores.
    fn commenter_id(&self) -> i64;

    /// Whether the user moderates comments: edits, removes, and moderates anyone's. `false` by
    /// default.
    fn is_moderator(&self) -> bool {
        false
    }
}

/// The author of a new comment.
#[derive(Debug)]
pub enum Author<'a, U> {
    /// One of the application's users.
    User(&'a U),
    /// Someone without an account, known by a name and an email address.
    Guest {
        /// The name shown with the comment.
        name: &'a str,
        /// The email address, which is never serialized.
        email: &'a str,
    },
}

impl<'a, U> Author<'a, U> {
    /// One of the application's users.
    #[must_use]
    pub const fn user(user: &'a U) -> Self {
        Self::User(user)
    }

    /// Someone without an account.
    #[must_use]
    pub const fn guest(name: &'a str, email: &'a str) -> Self {
        Self::Guest { name, email }
    }
}

// Written by hand: `Author` holds references, so it's `Copy` whatever the user model is.
impl<U> Clone for Author<'_, U> {
    fn clone(&self) -> Self {
        *self
    }
}

impl<U> Copy for Author<'_, U> {}