encore-dev 2.0.0

Rust SDK for Encore applications
Documentation
//! Type-level flags representing resource reference permissions.
//!
//! Each group of operations has a [`Yes`] or [`No`] flag, combined with
//! [`Flag::Or`] when multiple permissions are specified as a tuple. This module
//! is public because SDK trait bounds reference it, though application code
//! does not need to use it directly.

/// A permission flag that is granted.
pub enum Yes {}

/// A permission flag that is not granted.
pub enum No {}

/// A type-level boolean flag for combining permissions.
pub trait Flag {
    /// Logical OR of `Self` and `B`, representing the combined permissions of
    /// two permission sets.
    type Or<B: Flag>: Flag;
}

impl Flag for Yes {
    type Or<B: Flag> = Yes;
}

impl Flag for No {
    type Or<B: Flag> = B;
}

/// Implemented when a permission flag is granted ([`Yes`]).
///
/// `Perm` is the permission type reported in compiler diagnostics when the
/// required permission is missing.
#[diagnostic::on_unimplemented(
    message = "the reference does not grant the `{Perm}` permission",
    label = "`{Perm}` is not among this reference's permissions",
    note = "add `{Perm}` to the permissions in the reference's type argument"
)]
pub trait Granted<Perm> {}

impl<Perm> Granted<Perm> for Yes {}