pub struct Did {
pub ipns: String,
pub fragment: Option<String>,
}Expand description
A parsed did:ma: identifier.
Without a fragment this is a bare DID: did:ma:<ipns>.
With a fragment it becomes a DID URL: did:ma:<ipns>#<fragment>.
Constructors enforce strict fragment validation (strict in what we send).
Parsing via try_from is lenient (generous in what we receive).
§Examples
use ma_did::Did;
// Bare DID (identity)
let id = Did::new_identity("k51qzi5uqu5abc").unwrap();
assert!(id.is_bare());
assert_eq!(id.base_id(), "did:ma:k51qzi5uqu5abc");
// DID URL with auto-generated fragment
let url = Did::new_url("k51qzi5uqu5abc", None::<String>).unwrap();
assert!(url.is_url());
// Parse incoming DID URL (lenient)
let parsed = Did::try_from("did:ma:k51qzi5uqu5abc#lobby").unwrap();
assert_eq!(parsed.fragment.as_deref(), Some("lobby"));Fields§
§ipns: String§fragment: Option<String>Local atom/inbox name (for example an avatar inbox in a world). In practice this often matches a Kubo key name, but this coupling is loose.
Implementations§
Source§impl Did
impl Did
Sourcepub fn new_identity(ipns: impl Into<String>) -> Result<Did, MaError>
pub fn new_identity(ipns: impl Into<String>) -> Result<Did, MaError>
Create a bare DID (did:ma:<ipns>) with no fragment.
Sourcepub fn new_url(
ipns: impl Into<String>,
fragment: Option<impl Into<String>>,
) -> Result<Did, MaError>
pub fn new_url( ipns: impl Into<String>, fragment: Option<impl Into<String>>, ) -> Result<Did, MaError>
Create a DID URL (did:ma:<ipns>#<fragment>).
If fragment is None, a nanoid is generated automatically.
Provided fragments are validated as nanoids ([A-Za-z0-9_-]+).
pub fn base_id(&self) -> String
pub fn with_fragment(&self, fragment: impl Into<String>) -> Result<Did, MaError>
pub fn id(&self) -> String
pub fn parse(input: &str) -> Result<(String, Option<String>), MaError>
pub fn validate(input: &str) -> Result<(), MaError>
Sourcepub fn validate_url(input: &str) -> Result<(), MaError>
pub fn validate_url(input: &str) -> Result<(), MaError>
Validate that input is a DID URL (has a fragment).
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Did
impl<'de> Deserialize<'de> for Did
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Did, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Did, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Serialize for Did
impl Serialize for Did
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl Eq for Did
impl StructuralPartialEq for Did
Auto Trait Implementations§
impl Freeze for Did
impl RefUnwindSafe for Did
impl Send for Did
impl Sync for Did
impl Unpin for Did
impl UnsafeUnpin for Did
impl UnwindSafe for Did
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> 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.