AifEncodedScopeElement

Struct AifEncodedScopeElement 

Source
pub struct AifEncodedScopeElement {
    pub path: String,
    pub permissions: BitFlags<AifRestMethod>,
}
Expand description

An element as part of an AifEncodedScope, consisting of a path and a set of permissions which are specified as a set of REST methods.

See AifEncodedScope for more information and a usage example.

Can also be used as the single member of a LibdcafEncodedScope.

Fields§

§path: String

Identifier for the object of this scope element, given as a URI of a resource on a CoAP server.

Refer to section 2 of RFC 9237 for specification details.

§permissions: BitFlags<AifRestMethod>

Permissions for the object (identified by path) of this scope element, given as a set of REST (CoAP or HTTP) methods.

More specifically, this is a bitmask—see AifRestMethod for further explanation. Refer to section 2 of RFC 9237 for specification details.

Implementations§

Source§

impl AifEncodedScopeElement

Source

pub fn new<T, U>(path: T, permissions: U) -> AifEncodedScopeElement

Creates a new AifEncodedScopeElement over the given path and permissions.

§Example

Let’s take the example given in Table 2 of the RFC:

  +================+===================================+
  | URI-local-part | Permission Set                    |
  +================+===================================+
  | /a/make-coffee | POST, Dynamic-GET, Dynamic-DELETE |
  +----------------+-----------------------------------+

We could create an AifEncodedScopeElement from that data like this: (the make_bitflags macro is used for better readability, but is not required)

use dcaf::common::scope::{AifEncodedScopeElement, AifRestMethod};
let element = AifEncodedScopeElement::new(
   "/a/make-coffee", make_bitflags!(AifRestMethod::{Post | DynamicGet | DynamicDelete})
);
Source

pub fn try_from_bits<T>( path: T, permissions: u64, ) -> Result<AifEncodedScopeElement, InvalidAifEncodedScopeError>
where T: Into<String>,

Tries to create a new AifEncodedScopeElement from the given path and permissions.

permissions must be a valid bitmask of REST methods, as defined in section 3 of RFC 9237.

§Errors

If the given permissions do not correspond to a valid set of AifRestMethods as defined in section 3 of RFC 9237.

§Example

For example, say we want to encode ["/a/led", 5], where the 5 corresponds to GET and FETCH (due to 20 and 24):

let element = AifEncodedScopeElement::try_from_bits("/a/led", 5)?;
assert_eq!(element, AifEncodedScopeElement::new("/a/led", AifRestMethod::Get | AifRestMethod::Put));

This method returns a result because it’s possible to specify a bitmask that doesn’t represent a REST method (such as 231):

assert!(AifEncodedScopeElement::try_from_bits("no", u64::pow(2, 31)).is_err());

Trait Implementations§

Source§

impl Clone for AifEncodedScopeElement

Source§

fn clone(&self) -> AifEncodedScopeElement

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 Debug for AifEncodedScopeElement

Source§

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

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

impl Hash for AifEncodedScopeElement

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 AifEncodedScopeElement

Source§

fn eq(&self, other: &AifEncodedScopeElement) -> 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 Serialize for AifEncodedScopeElement

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

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

impl Eq for AifEncodedScopeElement

Source§

impl StructuralPartialEq for AifEncodedScopeElement

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Serialize for T
where T: Serialize + ?Sized,

Source§

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

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.