pub struct Account { /* private fields */ }Expand description
A Fediverse account identifier of the form acct:user@host.
See RFC 7565 for the canonical
definition of the acct: URI scheme.
§Examples
let a = Account::parse("acct:alice@example.com").unwrap();
assert_eq!(a.user(), "alice");
assert_eq!(a.host(), "example.com");
assert_eq!(a.to_string(), "acct:alice@example.com");
// Leading `@` is tolerated:
assert_eq!(Account::parse("@alice@example.com").unwrap(), a);Implementations§
Source§impl Account
impl Account
Sourcepub fn new(
user: impl Into<String>,
host: impl Into<String>,
) -> Result<Self, Error>
pub fn new( user: impl Into<String>, host: impl Into<String>, ) -> Result<Self, Error>
Constructs an Account from its components.
Both must be non-empty. The host is normalised using IDNA 2008 (Unicode → ASCII Punycode, lowercased) per RFC 7565 §7, so internationalised domain names are accepted and stored in their canonical Punycode form.
§Errors
Returns Error::InvalidAcct if user or host is empty, or if
host contains characters that IDNA cannot map to a valid DNS
label.
Sourcepub fn parse(input: &str) -> Result<Self, Error>
pub fn parse(input: &str) -> Result<Self, Error>
Parses a string into an Account.
Accepts the following forms:
acct:user@host@user@hostuser@host
§Errors
Returns Error::InvalidAcct if the string does not match any of
the supported forms or if any component is empty.
Sourcepub fn to_resource(&self) -> String
pub fn to_resource(&self) -> String
Returns the resource URI in canonical acct: form.
Sourcepub fn webfinger_url(&self) -> Result<Url, Error>
pub fn webfinger_url(&self) -> Result<Url, Error>
Builds the https://{host}/.well-known/webfinger?resource=… URL for
this account.
§Errors
Returns Error::InvalidUrl if the host is not a valid authority.
Sourcepub fn webfinger_url_with_scheme(&self, scheme: &str) -> Result<Url, Error>
pub fn webfinger_url_with_scheme(&self, scheme: &str) -> Result<Url, Error>
Builds the {scheme}://{host}/.well-known/webfinger?resource=… URL
for this account, allowing the caller to override the scheme.
Production code should always use Self::webfinger_url to ensure
https. The override exists to support test fixtures, local
development, and Tor hidden-service endpoints.
§Errors
Returns Error::InvalidUrl if the resulting URL is malformed.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Account
impl<'de> Deserialize<'de> for Account
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>,
impl Eq for Account
impl StructuralPartialEq for Account
Auto Trait Implementations§
impl Freeze for Account
impl RefUnwindSafe for Account
impl Send for Account
impl Sync for Account
impl Unpin for Account
impl UnsafeUnpin for Account
impl UnwindSafe for Account
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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
key and return true if they are equal.