pub struct TextEncodedScope(/* private fields */);Expand description
A scope encoded as a space-delimited list of strings, as defined in RFC 6749, section 1.3.
Note that the syntax specified in the RFC has to be followed:
scope = scope-token *( SP scope-token )
scope-token = 1*( %x21 / %x23-5B / %x5D-7E )§Example
You can create a TextEncodedScope from a space-separated string:
let scope = TextEncodedScope::try_from("first second third")?;
assert!(scope.elements().eq(["first", "second", "third"]));It’s also possible to pass in a vector of strings:
let scope = TextEncodedScope::try_from(vec!["first", "second", "third"])?;
assert!(scope.elements().eq(["first", "second", "third"]));
assert!(TextEncodedScope::try_from(vec!["not allowed"]).is_err());But note that you have to follow the syntax from the RFC (which implicitly specifies that given scopes can’t be empty):
assert!(TextEncodedScope::try_from("can't use \\ or \"").is_err());
assert!(TextEncodedScope::try_from(" no weird spaces ").is_err());
assert!(TextEncodedScope::try_from(vec![]).is_err());Implementations§
Source§impl TextEncodedScope
impl TextEncodedScope
Sourcepub fn elements(&self) -> impl Iterator<Item = &str>
pub fn elements(&self) -> impl Iterator<Item = &str>
Return the individual elements (i.e., access ranges) of this scope.
Post-condition: The returned iterator will not be empty, and none of its elements
may contain spaces ( ), double-quotes (") or backslashes (\\').
§Example
let simple = TextEncodedScope::try_from("this is a test")?;
assert!(simple.elements().eq(vec!["this", "is", "a", "test"]));Trait Implementations§
Source§impl Clone for TextEncodedScope
impl Clone for TextEncodedScope
Source§fn clone(&self) -> TextEncodedScope
fn clone(&self) -> TextEncodedScope
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for TextEncodedScope
impl Debug for TextEncodedScope
Source§impl Display for TextEncodedScope
impl Display for TextEncodedScope
Source§impl From<TextEncodedScope> for Scope
impl From<TextEncodedScope> for Scope
Source§fn from(value: TextEncodedScope) -> Self
fn from(value: TextEncodedScope) -> Self
Converts to this type from the input type.
Source§impl Hash for TextEncodedScope
impl Hash for TextEncodedScope
Source§impl PartialEq for TextEncodedScope
impl PartialEq for TextEncodedScope
Source§impl Serialize for TextEncodedScope
impl Serialize for TextEncodedScope
Source§impl TryFrom<&str> for TextEncodedScope
impl TryFrom<&str> for TextEncodedScope
Source§impl TryFrom<Scope> for TextEncodedScope
impl TryFrom<Scope> for TextEncodedScope
impl Eq for TextEncodedScope
impl StructuralPartialEq for TextEncodedScope
Auto Trait Implementations§
impl Freeze for TextEncodedScope
impl RefUnwindSafe for TextEncodedScope
impl Send for TextEncodedScope
impl Sync for TextEncodedScope
impl Unpin for TextEncodedScope
impl UnwindSafe for TextEncodedScope
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more