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: StringIdentifier 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
impl AifEncodedScopeElement
Sourcepub fn new<T, U>(path: T, permissions: U) -> AifEncodedScopeElement
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})
);Sourcepub fn try_from_bits<T>(
path: T,
permissions: u64,
) -> Result<AifEncodedScopeElement, InvalidAifEncodedScopeError>
pub fn try_from_bits<T>( path: T, permissions: u64, ) -> Result<AifEncodedScopeElement, InvalidAifEncodedScopeError>
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
impl Clone for AifEncodedScopeElement
Source§fn clone(&self) -> AifEncodedScopeElement
fn clone(&self) -> AifEncodedScopeElement
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more