encore-dev 2.0.0-alpha.17

Rust SDK for Encore applications
Documentation
//! The type-level machinery behind a reference's permission set: one flag per
//! group of operations, [`Yes`] or [`No`], which a tuple of permissions ORs
//! together. Public because the SDK's bounds name it; apps never write it.

/// A flag that is set.
pub enum Yes {}

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

/// A type-level boolean.
pub trait Flag {
    /// This flag or `B`: what two permission sets combined grant.
    type Or<B: Flag>: Flag;
}

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

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

/// Holds when a flag is set. `Perm` is the permission the flag stands for,
/// which the compiler's error names when it is not.
#[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 {}