don't
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(atproto): impl `Serialize` for `RecordUri` and add accessor methods

tjh f1aae069 835b1660

+29 -1
+29 -1
crates/atproto/src/uri.rs
··· 1 - use crate::did::OwnedDid; 1 + use crate::{Did, did::OwnedDid}; 2 2 3 3 /// A fully defined Atmosphere URI pointing to a record. 4 4 /// ··· 26 26 rkey, 27 27 } 28 28 } 29 + 30 + #[must_use] 31 + pub fn authority(&self) -> &Did { 32 + &self.authority 33 + } 34 + 35 + #[must_use] 36 + pub fn collection(&self) -> &str { 37 + &self.collection 38 + } 39 + 40 + #[must_use] 41 + pub fn rkey(&self) -> &str { 42 + &self.rkey 43 + } 29 44 } 30 45 31 46 #[derive(Debug, PartialEq, Eq, thiserror::Error)] ··· 51 36 Error, 52 37 } 53 38 39 + #[cfg(feature = "serde")] 54 40 fn parse(s: &str) -> Result<RecordUri, Error> { 55 41 let Some(uri) = s.strip_prefix("at://") else { 56 42 return Err(Error::Error); ··· 102 86 D: serde::Deserializer<'de>, 103 87 { 104 88 deserializer.deserialize_str(RecordUriVisitor) 89 + } 90 + } 91 + 92 + impl serde::Serialize for RecordUri { 93 + fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> 94 + where 95 + S: serde::Serializer, 96 + { 97 + serializer.serialize_str(&format!( 98 + "at://{}/{}/{}", 99 + self.authority, self.collection, self.rkey 100 + )) 105 101 } 106 102 } 107 103 }