pub struct Resource { /* private fields */ }Expand description
A WebFinger resource URI.
RFC 7033 uses the resource query parameter for the query target, which is a URI rather than a
relative reference. Resource stores that URI text after checking the URI syntax that this crate
relies on at request boundaries.
Validation is intentionally conservative:
- the value must start with an RFC 3986 URI scheme;
- the value must contain only raw RFC 3986 URI characters;
- every
%must start a complete percent escape; - raw non-ASCII text must already be percent-encoded; and
httpandhttpsresources must use the//authorityform before their host is exposed throughResource::host.
Common valid resources include acct:carol@example.com and
https://example.org/users/carol.
§Examples
Parse a valid acct: resource:
use webfinger_rs::Resource;
let resource = "acct:carol@example.com".parse::<Resource>()?;
assert_eq!(resource.as_str(), "acct:carol@example.com");Raw characters outside the URI character set are rejected. Percent-encode them inside the resource URI before putting that URI in the outer WebFinger query string:
use webfinger_rs::{Resource, ResourceError};
let error = "acct:carol{admin}@example.com"
.parse::<Resource>()
.unwrap_err();
assert!(matches!(error, ResourceError::InvalidCharacters));
let resource = "acct:carol%7Badmin%7D@example.com".parse::<Resource>()?;
assert_eq!(resource.as_str(), "acct:carol%7Badmin%7D@example.com");HTTP(S) resources must include an authority so host inference cannot treat opaque URI text as a host:
use webfinger_rs::{Resource, ResourceError};
let error = "https:example.org/profile"
.parse::<Resource>()
.unwrap_err();
assert!(matches!(error, ResourceError::MissingHttpAuthority));
let resource = "https://example.org/profile".parse::<Resource>()?;
assert_eq!(resource.host(), Some("example.org"));See RFC 7033 section 4.1 for the resource parameter, RFC 3986 section 2.1 for percent
encoding, RFC 3986 section 2.2 for reserved characters, RFC 3986 section 2.3 for
unreserved characters, RFC 3986 section 3.1 for URI schemes, and RFC 3986 section 3.2 for
authority.
Implementations§
Trait Implementations§
impl Eq for Resource
Source§impl Ord for Resource
impl Ord for Resource
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Resource
impl PartialOrd for Resource
impl StructuralPartialEq for Resource
Auto Trait Implementations§
impl Freeze for Resource
impl RefUnwindSafe for Resource
impl Send for Resource
impl Sync for Resource
impl Unpin for Resource
impl UnsafeUnpin for Resource
impl UnwindSafe for Resource
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.