pub enum DagCbor {
Null,
Bool(bool),
Unsigned(u64),
Negative(i128),
Bytes(Vec<u8>),
Text(String),
List(Vec<DagCbor>),
Map(Vec<(DagCbor, DagCbor)>),
Link(Cid),
}Expand description
A typed DAG-CBOR value.
Construction is deliberate (no From<&str> footguns): callers build the
exact shape they need via DagCbor::map / DagCbor::list / etc., so
the determinism rules (sorted keys, minimal ints, tag-42 links) are enforced
at encode time rather than relying on the input order.
Variants§
Null
Bool(bool)
Unsigned(u64)
Non-negative integer (CBOR major 0).
Negative(i128)
Negative integer (CBOR major 1); -1 - n.
Invariant: the wrapped value MUST be < 0. The variant encodes as
CBOR major type 1 (-1 - n); a non-negative n has no valid encoding
there and is a programmer error caught (loudly, in release too) at
DagCbor::encode. Construct negatives via literal i128 values
(DagCbor::Negative(-1)) — never compute Negative(x) from an
unbounded x without first checking x < 0.
Bytes(Vec<u8>)
Byte string (major 2).
Text(String)
UTF-8 text string (major 3).
List(Vec<DagCbor>)
Array (major 4), in given order.
Map(Vec<(DagCbor, DagCbor)>)
Map (major 5). Keys are stored in the existing native lexical text-byte
order at construction; public AT ordering is applied by
crate::atproto_cbor at its explicit boundary.
Link(Cid)
CID link — encoded as CBOR tag 42.
Implementations§
Source§impl DagCbor
impl DagCbor
Sourcepub fn str_map(
pairs: impl IntoIterator<Item = (impl Into<String>, DagCbor)>,
) -> Self
pub fn str_map( pairs: impl IntoIterator<Item = (impl Into<String>, DagCbor)>, ) -> Self
Convenience: build a map from key/value string pairs, sorted canonically.
Only string keys are supported here (the common case for records/commits).
For non-string keys build the Map variant manually.
Sourcepub fn list(items: impl IntoIterator<Item = DagCbor>) -> Self
pub fn list(items: impl IntoIterator<Item = DagCbor>) -> Self
Convenience: build a list.
Sourcepub fn decode(input: &[u8]) -> Result<Self>
pub fn decode(input: &[u8]) -> Result<Self>
Decode canonical DAG-CBOR bytes, enforcing the determinism constraints: sorted text keys, no duplicates, bounded recursion, and minimal integer and length widths on the wire.
pub fn as_str(&self) -> Result<&str>
pub fn as_bytes(&self) -> Result<&[u8]>
pub fn as_unsigned(&self) -> Result<u64>
pub fn as_link(&self) -> Result<&Cid>
pub fn as_map(&self) -> Result<&[(DagCbor, DagCbor)]>
pub fn as_list(&self) -> Result<&[DagCbor]>
pub fn is_null(&self) -> bool
Trait Implementations§
impl StructuralPartialEq for DagCbor
Auto Trait Implementations§
impl Freeze for DagCbor
impl RefUnwindSafe for DagCbor
impl Send for DagCbor
impl Sync for DagCbor
impl Unpin for DagCbor
impl UnsafeUnpin for DagCbor
impl UnwindSafe for DagCbor
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> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more