Skip to main content

AtUri

Struct AtUri 

Source
pub struct AtUri { /* private fields */ }
Expand description

A validated AT-URI.

Format: at://did-or-handle/collection/rkey

Implementations§

Source§

impl AtUri

Source

pub fn new(s: &str) -> Result<Self, InvalidAtUriError>

Parse and validate an AT-URI string.

Source

pub fn is_valid(s: &str) -> bool

Check whether a string is a valid AT-URI.

Source

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.

Source

pub fn authority(&self) -> &str

Return the authority (DID or handle).

Source

pub fn collection(&self) -> Option<&str>

Return the collection NSID, if present.

Source

pub fn rkey(&self) -> Option<&str>

Return the record key, if present.

Source

pub fn fragment(&self) -> Option<&str>

Return the fragment, if present.

Source

pub const fn protocol(&self) -> &'static str

The URI protocol — always "at:".

Source

pub fn origin(&self) -> String

The URI origin — at://<authority>. Analogous to URL.origin in browsers (and to the TS AtUri.origin getter).

Source

pub fn set_authority( &mut self, v: impl Into<String>, ) -> Result<(), InvalidAtUriError>

Replace the authority. Validates the new value as a DID or a handle before committing — a failed update leaves the URI unchanged.

Source

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).

Source

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.

Source

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.

Source

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 reference is a full AT-URI (at://…), it’s parsed in isolation and returned.
  • If reference starts with #, the fragment is replaced.
  • Otherwise, reference is 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.

Trait Implementations§

Source§

impl Clone for AtUri

Source§

fn clone(&self) -> AtUri

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AtUri

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for AtUri

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for AtUri

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl FromStr for AtUri

Source§

type Err = InvalidAtUriError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for AtUri

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for AtUri

Source§

fn eq(&self, other: &AtUri) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for AtUri

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for AtUri

Source§

impl StructuralPartialEq for AtUri

Auto Trait Implementations§

§

impl Freeze for AtUri

§

impl RefUnwindSafe for AtUri

§

impl Send for AtUri

§

impl Sync for AtUri

§

impl Unpin for AtUri

§

impl UnsafeUnpin for AtUri

§

impl UnwindSafe for AtUri

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,