pub struct AtUri { /* private fields */ }Expand description
A validated AT-URI.
Format: at://did-or-handle/collection/rkey
Implementations§
Source§impl AtUri
impl AtUri
Sourcepub fn new(s: &str) -> Result<Self, InvalidAtUriError>
pub fn new(s: &str) -> Result<Self, InvalidAtUriError>
Parse and validate an AT-URI string.
Sourcepub fn make(
authority: &str,
collection: Option<&str>,
rkey: Option<&str>,
) -> Result<Self, InvalidAtUriError>
pub fn make( authority: &str, collection: Option<&str>, rkey: Option<&str>, ) -> Result<Self, InvalidAtUriError>
Build an AT-URI from individual parts. The collection and rkey
are each optional, mirroring the TS AtUri.make(host, coll?, rkey?)
constructor. Every part is validated in the same way as the
full-string parser — calling make(h, None, Some(r)) (rkey
without collection) is an error.
Return the authority (DID or handle).
Sourcepub fn collection(&self) -> Option<&str>
pub fn collection(&self) -> Option<&str>
Return the collection NSID, if present.
Sourcepub fn origin(&self) -> String
pub fn origin(&self) -> String
The URI origin — at://<authority>. Analogous to URL.origin
in browsers (and to the TS AtUri.origin getter).
Replace the authority. Validates the new value as a DID or a handle before committing — a failed update leaves the URI unchanged.
Sourcepub fn set_collection(
&mut self,
v: Option<&str>,
) -> Result<(), InvalidAtUriError>
pub fn set_collection( &mut self, v: Option<&str>, ) -> Result<(), InvalidAtUriError>
Replace the collection NSID. Pass None to clear both
collection and rkey (an rkey without a collection is not a
valid AT-URI, so setting collection to None also drops rkey).
Sourcepub fn set_rkey(&mut self, v: Option<&str>) -> Result<(), InvalidAtUriError>
pub fn set_rkey(&mut self, v: Option<&str>) -> Result<(), InvalidAtUriError>
Replace the record key. Setting a rkey on a URI with no
collection is rejected — the spec requires coll/rkey together.
Sourcepub fn set_fragment(&mut self, v: Option<&str>) -> Result<(), InvalidAtUriError>
pub fn set_fragment(&mut self, v: Option<&str>) -> Result<(), InvalidAtUriError>
Replace the fragment. Pass None to clear it. Fragments must
start with / per the atproto syntax (they’re JSON Pointer
expressions), so a non-None value that doesn’t is rejected.
Sourcepub fn resolve(&self, reference: &str) -> Result<Self, InvalidAtUriError>
pub fn resolve(&self, reference: &str) -> Result<Self, InvalidAtUriError>
Resolve a reference relative to this URI.
Handles the two cases the atproto spec actually uses:
- If
referenceis a full AT-URI (at://…), it’s parsed in isolation and returned. - If
referencestarts with#, the fragment is replaced. - Otherwise,
referenceis treated as a path applied to this URI’s authority: an empty / single-segment / two-segment reference sets just the collection / collection + rkey.
This is a pragmatic subset of TS’s relative-URI handling — atproto doesn’t use the full RFC 3986 scheme-relative / host- relative escalation ladder, so replicating all of it would be yak-shaving.