Struct Rule

Source
pub struct Rule<D, T> { /* private fields */ }
Expand description

A Rule defines how a reference or set of references can be made canonical, i.e. have a top-level refs/* entry – see Pattern.

The Rule::allowed type is generic to allow for Allowed to be used for serialization and deserialization, however, the use of Rule::validate should be used to get a valid rule.

The Rule::threshold, similarly, allows for doc::Threshold to be used, and Rule::validate should be used to get a valid rule.

Implementations§

Source§

impl Rule<Allowed, usize>

Source

pub fn validate<R>( self, resolve: &mut R, ) -> Result<Rule<ResolvedDelegates, Threshold>, ValidationError>
where R: Fn() -> Delegates,

Validate the Rule into a form that can be used for calculating canonical references.

The resolve callback is to allow the caller to specify the DIDs of the identity document, in the case that the allowed value is Allowed::Delegates.

Source§

impl Rule<ResolvedDelegates, Threshold>

Source

pub fn default_branch( did: Did, name: &RefStr, ) -> Result<(Pattern, Rule<ResolvedDelegates, Threshold>), PatternError>

Initialize a ValidRule for the default branch, given by name. The rule will contain the single did as the allowed DID, and use a threshold of 1.

Note that the serialization of the rule will use the delegates token for the rule. E.g.

{
  "pattern": "refs/heads/main",
  "allow": ["did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi"],
  "threshold": 1
}
§Errors

If the name reference begins with refs/rad.

Source§

impl<D, T> Rule<D, T>

Source

pub fn new(allow: D, threshold: T) -> Rule<D, T>

Construct a new Rule with the given allow and threshold.

Source

pub fn allowed(&self) -> &D

Get the set of DIDs this Rule was created with.

Source

pub fn threshold(&self) -> &T

Get the set of threshold this Rule was created with.

Source

pub fn extensions(&self) -> &Map<String, Value>

Get the extensions that may have been added to this Rule.

Source

pub fn add_extensions(&mut self, extensions: impl Into<Map<String, Value>>)

If the Rule::extensions is not set, the provided extensions will be used.

Otherwise, it expects that the JSON value is a Map and the extensions are merged. If the existing value is any other kind of JSON value, this is a no-op.

Trait Implementations§

Source§

impl<D, T> Clone for Rule<D, T>
where D: Clone, T: Clone,

Source§

fn clone(&self) -> Rule<D, T>

Returns a duplicate 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<D, T> Debug for Rule<D, T>
where D: Debug, T: Debug,

Source§

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

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

impl<'de, D, T> Deserialize<'de> for Rule<D, T>
where D: Sealed + Deserialize<'de>, T: Sealed + Deserialize<'de>,

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Rule<D, T>, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<Rule<ResolvedDelegates, Threshold>> for Rule<Allowed, usize>

Source§

fn from(rule: Rule<ResolvedDelegates, Threshold>) -> Rule<Allowed, usize>

Converts to this type from the input type.
Source§

impl<D, T> PartialEq for Rule<D, T>
where D: PartialEq, T: PartialEq,

Source§

fn eq(&self, other: &Rule<D, T>) -> 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<D, T> Serialize for Rule<D, T>
where D: Serialize, T: Serialize,

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<D, T> Eq for Rule<D, T>
where D: Eq, T: Eq,

Source§

impl<D, T> StructuralPartialEq for Rule<D, T>

Auto Trait Implementations§

§

impl<D, T> Freeze for Rule<D, T>
where D: Freeze, T: Freeze,

§

impl<D, T> RefUnwindSafe for Rule<D, T>

§

impl<D, T> Send for Rule<D, T>
where D: Send, T: Send,

§

impl<D, T> Sync for Rule<D, T>
where D: Sync, T: Sync,

§

impl<D, T> Unpin for Rule<D, T>
where D: Unpin, T: Unpin,

§

impl<D, T> UnwindSafe for Rule<D, T>
where D: UnwindSafe, T: UnwindSafe,

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<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<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> IntoInit<ZeroInit> for T

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

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, 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,