pub struct DidUrl { /* private fields */ }Expand description
A DID URL such as did:example:123/path?versionId=1#key-1.
A DidUrl is a Did followed by an optional path, query and fragment as defined by
W3C DID Core §3.2 and RFC 3986. It is validated on construction and stores the input unchanged.
A DidUrl without path, query or fragment displays as the bare DID.
Equality, ordering and hashing are those of the URL string.
§Examples
use identity_kit::did::DidUrl;
let url = DidUrl::parse("did:example:123/path/to?versionId=1#frag")?;
assert_eq!(url.did().as_str(), "did:example:123");
assert_eq!(url.path(), Some("/path/to"));
assert_eq!(url.query(), Some("versionId=1"));
assert_eq!(url.fragment(), Some("frag"));
let key = DidUrl::parse("did:example:123#key-1")?;
assert_eq!(key.path(), None);
assert_eq!(key.without_fragment().as_str(), "did:example:123");
assert_eq!(key.with_fragment("key-2").as_str(), "did:example:123#key-2");Implementations§
Source§impl DidUrl
impl DidUrl
Sourcepub fn parse(s: &str) -> Result<Self, DidError>
pub fn parse(s: &str) -> Result<Self, DidError>
Parses a DID URL, rejecting input longer than DEFAULT_MAX_LEN bytes.
§Errors
Returns a DidError describing the first violation of the DID URL syntax.
§Examples
use identity_kit::did::{DidError, DidUrl};
let url = DidUrl::parse("did:example:123?service=agent&relativeRef=%2Fsome%2Fpath")?;
assert_eq!(url.query(), Some("service=agent&relativeRef=%2Fsome%2Fpath"));
// An empty fragment is present but empty, as in RFC 3986.
assert_eq!(DidUrl::parse("did:example:123#")?.fragment(), Some(""));
assert_eq!(DidUrl::parse("did:example:123#a#b"), Err(DidError::InvalidFragment));Sourcepub fn parse_with_max_len(s: &str, max_len: usize) -> Result<Self, DidError>
pub fn parse_with_max_len(s: &str, max_len: usize) -> Result<Self, DidError>
Parses a DID URL, rejecting input longer than max_len bytes with DidError::TooLong.
§Errors
Returns a DidError describing the first violation of the DID URL syntax.
Sourcepub fn path(&self) -> Option<&str>
pub fn path(&self) -> Option<&str>
The path, starting with /, or None when the URL has no path.
Sourcepub fn query(&self) -> Option<&str>
pub fn query(&self) -> Option<&str>
The query without the leading ?, or None when the URL has no ?.
Sourcepub fn fragment(&self) -> Option<&str>
pub fn fragment(&self) -> Option<&str>
The fragment without the leading #, or None when the URL has no #.
Sourcepub fn with_fragment(&self, fragment: &str) -> Self
pub fn with_fragment(&self, fragment: &str) -> Self
A copy of this URL with its fragment replaced by fragment.
fragment is taken as already percent-encoded: a % followed by two hexadecimal digits is
kept, and every other byte that RFC 3986 does not allow in a fragment (including a stray
%) is percent-encoded, so the result is always a valid DID URL.
§Examples
use identity_kit::did::DidUrl;
let url = DidUrl::parse("did:example:123?versionId=1#key-1")?;
assert_eq!(url.with_fragment("key-2").as_str(), "did:example:123?versionId=1#key-2");
assert_eq!(url.with_fragment("a b").fragment(), Some("a%20b"));Sourcepub fn with_did(&self, did: Did) -> Self
pub fn with_did(&self, did: Did) -> Self
A copy of this URL with its DID replaced by did, keeping path, query and fragment.
§Examples
use identity_kit::did::{Did, DidUrl};
let url = DidUrl::parse("did:example:123/path?versionId=1#key-1")?;
let moved = url.with_did(Did::parse("did:web:example.com")?);
assert_eq!(moved.as_str(), "did:web:example.com/path?versionId=1#key-1");
assert_eq!(moved.fragment(), Some("key-1"));Sourcepub fn without_fragment(&self) -> Self
pub fn without_fragment(&self) -> Self
A copy of this URL without a fragment.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for DidUrl
impl<'de> Deserialize<'de> for DidUrl
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
impl Eq for DidUrl
Source§impl From<&DidUrl> for DidUrlReference
impl From<&DidUrl> for DidUrlReference
Source§impl From<DidUrl> for DidUrlReference
impl From<DidUrl> for DidUrlReference
Source§impl Ord for DidUrl
impl Ord for DidUrl
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for DidUrl
impl PartialOrd for DidUrl
Auto Trait Implementations§
impl Freeze for DidUrl
impl RefUnwindSafe for DidUrl
impl Send for DidUrl
impl Sync for DidUrl
impl Unpin for DidUrl
impl UnsafeUnpin for DidUrl
impl UnwindSafe for DidUrl
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
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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.