pub struct URL {
pub did: DID,
pub parameters: Option<URLParameters>,
}
Expand description
DID URL handling, including parsing, (de)-serialization, and manipulation according to https://www.w3.org/TR/did-core/#did-url-syntax.
DID URLs are nothing like hypertext URLs and it is strongly cautioned that you do not treat them as such.
The struct includes a DID as well as optional URLParameters to extend the DID. Converting to string, formatting for display, or serialization will cause the URL to be generated.
use did_toolkit::prelude::*;
let url = URL::parse("did:mymethod:alice/path?service=foo#fragment").unwrap();
assert_eq!(url, URL {
did: DID::parse("did:mymethod:alice").unwrap(),
parameters: Some(URLParameters{
path: Some("path".as_bytes().to_vec()),
fragment: Some("fragment".as_bytes().to_vec()),
service: Some("foo".to_string()),
..Default::default()
})
});
let url = URL {
did: DID::parse("did:mymethod:bob").unwrap(),
parameters: Some(URLParameters{
path: Some("path".as_bytes().to_vec()),
fragment: Some("fragment".as_bytes().to_vec()),
service: Some("bar".to_string()),
version_id: Some("1.0".to_string()),
..Default::default()
})
};
assert_eq!(url.to_string(), "did:mymethod:bob/path?service=bar&versionId=1.0#fragment");
Fields§
§did: DID
§parameters: Option<URLParameters>
Implementations§
Trait Implementations§
Source§impl<'de> Deserialize<'de> for URL
impl<'de> Deserialize<'de> for URL
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Ord for URL
impl Ord for URL
Source§impl PartialOrd for URL
impl PartialOrd for URL
impl Eq for URL
impl StructuralPartialEq for URL
Auto Trait Implementations§
impl Freeze for URL
impl RefUnwindSafe for URL
impl Send for URL
impl Sync for URL
impl Unpin for URL
impl UnwindSafe for URL
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
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
Compare self to
key
and return true
if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more