pub enum DidUrlReference {
Absolute(DidUrl),
Relative(String),
}Expand description
A reference to a resource of a DID document: either an absolute DidUrl or a relative DID
URL (DID Core §3.2.2) such as #key-1, which is resolved against the document’s id.
Verification relationships reference verification methods this way, and a document may use
either form, so the reference keeps whichever it was given and resolve
turns it into an absolute DID URL when a base DID is known.
A relative reference is a path, query and fragment (any of them, in that order), so it starts
with /, ? or #.
§Examples
use identity_kit::did::{Did, DidUrlReference};
let base: Did = "did:example:123".parse()?;
let relative = DidUrlReference::parse("#key-1")?;
assert!(relative.is_relative());
assert_eq!(relative.resolve(&base)?.as_str(), "did:example:123#key-1");
let absolute = DidUrlReference::parse("did:example:456#key-1")?;
assert!(!absolute.is_relative());
assert_eq!(absolute.resolve(&base)?.as_str(), "did:example:456#key-1");Variants§
Absolute(DidUrl)
A DID URL.
Relative(String)
A relative DID URL: /path, ?query or #fragment, possibly combined, as written.
Implementations§
Source§impl DidUrlReference
impl DidUrlReference
Sourcepub fn parse(s: &str) -> Result<Self, DidError>
pub fn parse(s: &str) -> Result<Self, DidError>
Parses a DID URL or a relative DID URL, rejecting input longer than DEFAULT_MAX_LEN
bytes.
§Errors
A DidError when the input is neither a valid DID URL nor a relative reference starting
with /, ? or # whose components are valid per RFC 3986. Positions in the error are
byte offsets into the input.
Sourcepub fn is_relative(&self) -> bool
pub fn is_relative(&self) -> bool
Whether this is a relative reference.
Sourcepub fn resolve(&self, base: &Did) -> Result<DidUrl, DidError>
pub fn resolve(&self, base: &Did) -> Result<DidUrl, DidError>
The absolute DID URL, resolving a relative reference against base as RFC 3986 §5
prescribes for a DID document (DID Core §3.2.2).
§Errors
DidError::TooLong when base and a relative reference together exceed
DEFAULT_MAX_LEN bytes, the limit Did::join keeps to.
Trait Implementations§
Source§impl AsRef<str> for DidUrlReference
impl AsRef<str> for DidUrlReference
Source§impl Clone for DidUrlReference
impl Clone for DidUrlReference
Source§impl Debug for DidUrlReference
impl Debug for DidUrlReference
Source§impl<'de> Deserialize<'de> for DidUrlReference
impl<'de> Deserialize<'de> for DidUrlReference
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Source§impl Display for DidUrlReference
impl Display for DidUrlReference
impl Eq for DidUrlReference
Source§impl From<&DidUrl> for DidUrlReference
impl From<&DidUrl> for DidUrlReference
Source§impl From<DidUrl> for DidUrlReference
impl From<DidUrl> for DidUrlReference
Source§impl From<DidUrlReference> for MethodRef
impl From<DidUrlReference> for MethodRef
Source§fn from(reference: DidUrlReference) -> Self
fn from(reference: DidUrlReference) -> Self
Source§impl FromStr for DidUrlReference
impl FromStr for DidUrlReference
Source§impl Hash for DidUrlReference
impl Hash for DidUrlReference
Source§impl Ord for DidUrlReference
impl Ord for DidUrlReference
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 PartialEq for DidUrlReference
impl PartialEq for DidUrlReference
Source§impl PartialOrd for DidUrlReference
impl PartialOrd for DidUrlReference
Source§impl Serialize for DidUrlReference
impl Serialize for DidUrlReference
impl StructuralPartialEq for DidUrlReference
Source§impl TryFrom<&str> for DidUrlReference
impl TryFrom<&str> for DidUrlReference
Auto Trait Implementations§
impl Freeze for DidUrlReference
impl RefUnwindSafe for DidUrlReference
impl Send for DidUrlReference
impl Sync for DidUrlReference
impl Unpin for DidUrlReference
impl UnsafeUnpin for DidUrlReference
impl UnwindSafe for DidUrlReference
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.