Expand description
AT Protocol identifier types with validation.
Provides validated newtypes for all AT Protocol identifiers:
DID, Handle, NSID, AT-URI, TID, RecordKey, Datetime, and AtIdentifier.
§Examples
use proto_blue_syntax::{Did, Handle, Nsid, AtUri, Tid, RecordKey};
// Parse and validate a DID
let did = Did::new("did:plc:z72i7hdynmk6r22z27h6tvur").unwrap();
assert_eq!(did.method(), "plc");
// Parse a handle
let handle = Handle::new("alice.bsky.social").unwrap();
assert_eq!(handle.to_string(), "alice.bsky.social");
// Parse an NSID
let nsid = Nsid::new("app.bsky.feed.post").unwrap();
assert_eq!(nsid.authority(), "app.bsky.feed");
assert_eq!(nsid.name(), "post");
// Parse an AT-URI
let uri = AtUri::new("at://did:plc:z72i7hdynmk6r22z27h6tvur/app.bsky.feed.post/abc123").unwrap();
assert_eq!(uri.collection(), Some("app.bsky.feed.post"));
assert_eq!(uri.rkey(), Some("abc123"));
// Generate a TID from a timestamp
let tid = Tid::from_timestamp(1704067200_000_000, 0);
assert_eq!(tid.to_string().len(), 13);
// Validate a record key
let rkey = RecordKey::new("self").unwrap();
assert!(RecordKey::new(".").is_err()); // "." is not allowedStructs§
- AtUri
- A validated AT-URI.
- Datetime
- A validated AT Protocol datetime string.
- Did
- A validated DID (Decentralized Identifier).
- Handle
- A validated AT Protocol handle.
- Invalid
AtIdentifier Error - Error returned when an AT identifier string is invalid.
- Invalid
AtUri Error - Error returned when an AT-URI string is invalid.
- Invalid
Datetime Error - Error returned when a datetime string is invalid.
- Invalid
DidError - Error returned when a DID string is invalid.
- Invalid
Handle Error - Error returned when a handle string is invalid.
- Invalid
Nsid Error - Error returned when an NSID string is invalid.
- Invalid
Record KeyError - Error returned when a record key string is invalid.
- Invalid
TidError - Error returned when a TID string is invalid.
- Nsid
- A validated NSID (Namespaced Identifier).
- Record
Key - A validated record key.
- Tid
- A validated TID (Timestamp Identifier).
Enums§
- AtIdentifier
- A validated AT identifier (either a DID or a Handle).
Constants§
- DISALLOWED_
TLDS - TLDs that are disallowed for handles.
- HANDLE_
INVALID - The canonical invalid handle value.
Functions§
- current_
datetime_ string - Free-function shortcut for
Datetime::now, matching TS naming. - is_
valid_ language - Check if a string is a valid BCP 47 language tag.
- is_
valid_ tld trueif the handle ends in a TLD that AT Protocol forbids for handles (.local,.arpa,.onion, etc.). Mirrors TSisValidTldin@atproto/syntax.- is_
valid_ uri truewhensparses as a minimally-valid URI — an RFC 3986 scheme followed by a colon and at least one further character.- normalize_
and_ ensure_ valid_ handle - Normalise + validate in one step. Returns the canonical lowercase
form on success. Mirrors TS
normalizeAndEnsureValidHandle. - normalize_
datetime - Normalize a datetime string to canonical
YYYY-MM-DDTHH:mm:ss.sssZform. - normalize_
handle - Normalise a raw handle string to its canonical form (ASCII
lowercase). Does not validate the handle — use
Handle::newif you want validation. Mirrors TSnormalizeHandle.