Skip to main content

Role

Struct Role 

Source
pub struct Role { /* private fields */ }
Expand description

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

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");

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.

Implementations§

Source§

impl Role

Source

pub fn new( name: RoleName, identifier: impl Into<String>, dimension: impl Into<String>, ) -> Self

new Role($role, $identifier, $dimension).

Source

pub fn named( name: &str, identifier: impl Into<String>, dimension: impl Into<String>, ) -> Self

A role from its name as text (new Role('team', ...)).

Source

pub fn name(&self) -> &RoleName

The name (getRole()).

Source

pub fn identifier(&self) -> &str

The identifier, empty when none (getIdentifier()).

Source

pub fn dimension(&self) -> &str

The dimension, empty when none (getDimension()).

Source

pub fn parse(role: &str) -> Result<Self>

Role::parse($role): name, name:identifier, name/dimension or name:identifier/dimension. Only the first : separates the identifier; text after a second : is dropped, as PHP does.

Fails (crate::Kind::Exception, PHP’s \Exception) with Only one dimension can be provided or Dimension must not be empty.

Source

pub fn user(identifier: impl Into<String>, status: impl Into<String>) -> Self

Role::user($identifier, $status).

Source

pub fn users(status: impl Into<String>) -> Self

Role::users($status).

Source

pub fn team(identifier: impl Into<String>, dimension: impl Into<String>) -> Self

Role::team($identifier, $dimension).

Source

pub fn label(identifier: impl Into<String>) -> Self

Role::label($identifier).

Source

pub fn any() -> Self

Role::any().

Source

pub fn guests() -> Self

Role::guests().

Source

pub fn member(identifier: impl Into<String>) -> Self

Role::member($identifier).

Trait Implementations§

Source§

impl Clone for Role

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Role

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Role

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

toString(): name, then :identifier and /dimension when they are truthy.

Source§

impl Eq for Role

Source§

impl Hash for Role

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Role

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Role

Auto Trait Implementations§

§

impl Forget for Role

§

impl Freeze for Role

§

impl Move for Role

§

impl RefUnwindSafe for Role

§

impl Send for Role

§

impl Sync for Role

§

impl Unpin for Role

§

impl UnsafeUnpin for Role

§

impl UnwindSafe for Role

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.