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<Self>
pub fn new_identity(ipns: impl Into<String>) -> Result<Self>
Create a bare DID (did:ma:<ipns>) with no fragment.
Sourcepub fn new_url(
ipns: impl Into<String>,
fragment: Option<impl Into<String>>,
) -> Result<Self>
pub fn new_url( ipns: impl Into<String>, fragment: Option<impl Into<String>>, ) -> Result<Self>
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<Self>
pub fn id(&self) -> String
pub fn parse(input: &str) -> Result<(String, Option<String>)>
pub fn validate(input: &str) -> Result<()>
Sourcepub fn validate_url(input: &str) -> Result<()>
pub fn validate_url(input: &str) -> Result<()>
Validate that input is a DID URL (has a fragment).
Sourcepub fn validate_identity(input: &str) -> Result<()>
pub fn validate_identity(input: &str) -> Result<()>
Validate that input is a bare DID identity (no fragment).
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Did
impl<'de> Deserialize<'de> for Did
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
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