Rust

role

Module

[Role]: who a permission is granted to (any, users, user:<id>, team:<id>/<dimension>, ...).

PHP: Utopia\Database\Role.

Contents

use utopia_database::Role;
Rust
pub struct Role {
    // private fields
}

A role: a name, an optional identifier and an optional dimension, written name:identifier/dimension.

PHP: Utopia\Database\Role. As in PHP, an identifier or a dimension of "0" is falsy: Role::to_string leaves it out, and Role::parse rejects a "0" dimension as empty.

Rust
use utopia_database::Role;

let role = Role::parse("team:123/owner").unwrap();
assert_eq!(role.name().as_str(), "team");
assert_eq!(role.identifier(), "123");
assert_eq!(role.dimension(), "owner");
assert_eq!(Role::user("123", "verified").to_string(), "user:123/verified");
assert_eq!(Role::parse("users/a/b").unwrap_err().message(), "Only one dimension can be provided");
Also implements Display.
use utopia_database::role::RoleName;
Rust
pub enum RoleName {
    Any,
    Guests,
    Users,
    User,
    Team,
    Member,
    Label,
    Other(String),
}

The name of a role: one of the roles the library knows, or any other name (PHP parses and stores roles it does not know).

PHP: the $role string of Role (Validator\Roles::ROLE_* for the known ones).