Struct cedar_policy::PolicySet

source ·
pub struct PolicySet { /* private fields */ }
Expand description

Represents a set of Policys

Implementations§

source§

impl PolicySet

source

pub fn new() -> Self

Create a fresh empty PolicySet

source

pub fn from_policies( policies: impl IntoIterator<Item = Policy>, ) -> Result<Self, PolicySetError>

Create a PolicySet from the given policies

source

pub fn add(&mut self, policy: Policy) -> Result<(), PolicySetError>

Add an static policy to the PolicySet. To add a template instance, use link instead. This function will return an error (and not modify the PolicySet) if a template-linked policy is passed in. If a link, template or static policy with this ID already exists, this will error.

source

pub fn add_template(&mut self, template: Template) -> Result<(), PolicySetError>

Add a Template to the PolicySet If a link, template or static policy with this ID already exists, this will error.

source

pub fn policies(&self) -> impl Iterator<Item = &Policy>

Iterate over all the Policys in the PolicySet.

This will include both static and template-linked policies.

source

pub fn templates(&self) -> impl Iterator<Item = &Template>

Iterate over the Template’s in the PolicySet.

source

pub fn template(&self, id: &PolicyId) -> Option<&Template>

Get a Template by its PolicyId

source

pub fn policy(&self, id: &PolicyId) -> Option<&Policy>

Get a Policy by its PolicyId

source

pub fn annotation<'a>( &'a self, id: &PolicyId, key: impl AsRef<str>, ) -> Option<&'a str>

Extract annotation data from a Policy by its PolicyId and annotation key

source

pub fn template_annotation( &self, id: &PolicyId, key: impl AsRef<str>, ) -> Option<String>

Extract annotation data from a Template by its PolicyId and annotation key.

source

pub fn is_empty(&self) -> bool

Returns true iff the PolicySet is empty

source

pub fn num_of_policies(&self) -> usize

Returns the number of Policys in the PolicySet.

This will include both static and template-linked policies.

source

pub fn num_of_templates(&self) -> usize

Returns the number of Templates in the PolicySet.

Attempt to link a template and add the new template-linked policy to the policy set. If link fails, the PolicySet is not modified. Failure can happen for three reasons

  1. The map passed in vals may not match the slots in the template
  2. The new_id may conflict w/ a policy that already exists in the set If a link, template or static policy with this ID already exists, this will error.

Trait Implementations§

source§

impl Clone for PolicySet

source§

fn clone(&self) -> PolicySet

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for PolicySet

source§

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

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

impl Default for PolicySet

source§

fn default() -> PolicySet

Returns the “default value” for a type. Read more
source§

impl Display for PolicySet

source§

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

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

impl FromStr for PolicySet

source§

fn from_str(policies: &str) -> Result<Self, Self::Err>

Create a policy set from multiple statements.

Policy ids will default to “policy*” with numbers from 0. If you load more policies, do not use the default id, or there will be conflicts.

See Policy for more.

source§

type Err = ParseErrors

The associated error which can be returned from parsing.
source§

impl PartialEq for PolicySet

source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for PolicySet

Auto Trait Implementations§

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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> ToSmolStr for T
where T: Display + ?Sized,

source§

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

source§

default 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.