Data

Enum Data 

Source
pub enum Data<'s> {
    Null,
    Boolean(bool),
    Integer(i64),
    String(AtprotoStr<'s>),
    Bytes(Bytes),
    CidLink(Cid<'s>),
    Array(Array<'s>),
    Object(Object<'s>),
    Blob(Blob<'s>),
}
Expand description

AT Protocol data model value

Represents any valid value in the AT Protocol data model, which supports JSON and CBOR serialization with specific constraints (no floats, CID links, blobs with metadata).

This is the generic “unknown data” type used for lexicon values, extra fields captured by #[lexicon], and IPLD data structures.

Variants§

§

Null

Null value

§

Boolean(bool)

Boolean value

§

Integer(i64)

Integer value (no floats in AT Protocol)

§

String(AtprotoStr<'s>)

String value (parsed into specific AT Protocol types when possible)

§

Bytes(Bytes)

Raw bytes

CID link reference

§

Array(Array<'s>)

Array of values

§

Object(Object<'s>)

Object/map of values

§

Blob(Blob<'s>)

Blob reference with metadata

Implementations§

Source§

impl<'s> Data<'s>

Source

pub fn data_type(&self) -> DataModelType

Get the data model type of this value

Source

pub fn from_json(json: &'s Value) -> Result<Self, AtDataError>

Parse a Data value from a JSON value

Source

pub fn from_cbor(cbor: &'s Ipld) -> Result<Self, AtDataError>

Parse a Data value from an IPLD value (CBOR)

Trait Implementations§

Source§

impl<'s> Clone for Data<'s>

Source§

fn clone(&self) -> Data<'s>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'s> Debug for Data<'s>

Source§

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

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

impl<'de, 'a> Deserialize<'de> for Data<'a>
where 'de: 'a,

Source§

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

Currently only works for self-describing formats Thankfully the supported atproto data formats are both self-describing (json and dag-cbor). TODO: see if there’s any way to make this work with Postcard.

Source§

impl From<&[u8]> for Data<'_>

Source§

fn from(t: &[u8]) -> Self

Converts to this type from the input type.
Source§

impl<'s> From<&Cid<'s>> for Data<'s>

Source§

fn from(t: &Cid<'s>) -> Self

Converts to this type from the input type.
Source§

impl From<&str> for Data<'_>

Source§

fn from(t: &str) -> Self

Converts to this type from the input type.
Source§

impl<'s> From<Array<'s>> for Data<'s>

Source§

fn from(t: Array<'s>) -> Self

Converts to this type from the input type.
Source§

impl<'s> From<Box<[u8]>> for Data<'s>

Source§

fn from(t: Box<[u8]>) -> Self

Converts to this type from the input type.
Source§

impl<'s> From<Cid<'s>> for Data<'s>

Source§

fn from(t: Cid<'s>) -> Self

Converts to this type from the input type.
Source§

impl<'s> From<Object<'s>> for Data<'s>

Source§

fn from(t: Object<'s>) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Data<'_>

Source§

fn from(t: String) -> Self

Converts to this type from the input type.
Source§

impl<'s> From<Vec<u8>> for Data<'s>

Source§

fn from(t: Vec<u8>) -> Self

Converts to this type from the input type.
Source§

impl<'s> From<bool> for Data<'s>

Source§

fn from(t: bool) -> Self

Converts to this type from the input type.
Source§

impl<'s> From<i128> for Data<'s>

Source§

fn from(t: i128) -> Self

Converts to this type from the input type.
Source§

impl<'s> From<i16> for Data<'s>

Source§

fn from(t: i16) -> Self

Converts to this type from the input type.
Source§

impl<'s> From<i32> for Data<'s>

Source§

fn from(t: i32) -> Self

Converts to this type from the input type.
Source§

impl<'s> From<i64> for Data<'s>

Source§

fn from(t: i64) -> Self

Converts to this type from the input type.
Source§

impl<'s> From<i8> for Data<'s>

Source§

fn from(t: i8) -> Self

Converts to this type from the input type.
Source§

impl<'s> From<isize> for Data<'s>

Source§

fn from(t: isize) -> Self

Converts to this type from the input type.
Source§

impl<'s> From<u16> for Data<'s>

Source§

fn from(t: u16) -> Self

Converts to this type from the input type.
Source§

impl<'s> From<u32> for Data<'s>

Source§

fn from(t: u32) -> Self

Converts to this type from the input type.
Source§

impl<'s> From<u64> for Data<'s>

Source§

fn from(t: u64) -> Self

Converts to this type from the input type.
Source§

impl<'s> From<u8> for Data<'s>

Source§

fn from(t: u8) -> Self

Converts to this type from the input type.
Source§

impl<'s> From<usize> for Data<'s>

Source§

fn from(t: usize) -> Self

Converts to this type from the input type.
Source§

impl IntoStatic for Data<'_>

Source§

type Output = Data<'static>

The “owned” variant of the type. For Cow<'a, str>, this is Cow<'static, str>, for example.
Source§

fn into_static(self) -> Data<'static>

Turns the value into an “owned” variant, which can then be returned, moved, etc. Read more
Source§

impl<'s> PartialEq for Data<'s>

Source§

fn eq(&self, other: &Data<'s>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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 Data<'_>

Source§

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

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

impl TryFrom<Data<'_>> for ()

Source§

type Error = ConversionError

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

fn try_from(ipld: Data<'_>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'s> TryFrom<Data<'s>> for Option<String>

Source§

type Error = ConversionError

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

fn try_from(ipld: Data<'s>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'s> TryFrom<Data<'s>> for String

Source§

type Error = ConversionError

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

fn try_from(ipld: Data<'s>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Data<'static>> for Cid<'static>

Source§

type Error = ConversionError

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

fn try_from(ipld: Data<'static>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Data<'static>> for Object<'static>

Source§

type Error = ConversionError

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

fn try_from(ipld: Data<'static>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Data<'static>> for Option<Array<'static>>

Source§

type Error = ConversionError

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

fn try_from(ipld: Data<'static>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Data<'static>> for Option<Cid<'static>>

Source§

type Error = ConversionError

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

fn try_from(ipld: Data<'static>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Data<'static>> for Option<Object<'static>>

Source§

type Error = ConversionError

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

fn try_from(ipld: Data<'static>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Data<'static>> for Option<Vec<u8>>

Source§

type Error = ConversionError

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

fn try_from(ipld: Data<'static>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Data<'static>> for Option<bool>

Source§

type Error = ConversionError

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

fn try_from(ipld: Data<'static>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Data<'static>> for Option<i128>

Source§

type Error = ConversionError

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

fn try_from(ipld: Data<'static>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Data<'static>> for Option<i16>

Source§

type Error = ConversionError

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

fn try_from(ipld: Data<'static>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Data<'static>> for Option<i32>

Source§

type Error = ConversionError

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

fn try_from(ipld: Data<'static>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Data<'static>> for Option<i64>

Source§

type Error = ConversionError

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

fn try_from(ipld: Data<'static>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Data<'static>> for Option<i8>

Source§

type Error = ConversionError

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

fn try_from(ipld: Data<'static>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Data<'static>> for Option<isize>

Source§

type Error = ConversionError

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

fn try_from(ipld: Data<'static>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Data<'static>> for Option<u128>

Source§

type Error = ConversionError

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

fn try_from(ipld: Data<'static>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Data<'static>> for Option<u16>

Source§

type Error = ConversionError

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

fn try_from(ipld: Data<'static>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Data<'static>> for Option<u32>

Source§

type Error = ConversionError

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

fn try_from(ipld: Data<'static>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Data<'static>> for Option<u64>

Source§

type Error = ConversionError

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

fn try_from(ipld: Data<'static>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Data<'static>> for Option<u8>

Source§

type Error = ConversionError

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

fn try_from(ipld: Data<'static>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Data<'static>> for Option<usize>

Source§

type Error = ConversionError

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

fn try_from(ipld: Data<'static>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Data<'static>> for Vec<u8>

Source§

type Error = ConversionError

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

fn try_from(ipld: Data<'static>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Data<'static>> for bool

Source§

type Error = ConversionError

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

fn try_from(ipld: Data<'static>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Data<'static>> for i128

Source§

type Error = ConversionError

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

fn try_from(ipld: Data<'static>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Data<'static>> for i16

Source§

type Error = ConversionError

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

fn try_from(ipld: Data<'static>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Data<'static>> for i32

Source§

type Error = ConversionError

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

fn try_from(ipld: Data<'static>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Data<'static>> for i64

Source§

type Error = ConversionError

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

fn try_from(ipld: Data<'static>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Data<'static>> for i8

Source§

type Error = ConversionError

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

fn try_from(ipld: Data<'static>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Data<'static>> for isize

Source§

type Error = ConversionError

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

fn try_from(ipld: Data<'static>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Data<'static>> for u128

Source§

type Error = ConversionError

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

fn try_from(ipld: Data<'static>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Data<'static>> for u16

Source§

type Error = ConversionError

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

fn try_from(ipld: Data<'static>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Data<'static>> for u32

Source§

type Error = ConversionError

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

fn try_from(ipld: Data<'static>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Data<'static>> for u64

Source§

type Error = ConversionError

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

fn try_from(ipld: Data<'static>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Data<'static>> for u8

Source§

type Error = ConversionError

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

fn try_from(ipld: Data<'static>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Data<'static>> for usize

Source§

type Error = ConversionError

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

fn try_from(ipld: Data<'static>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'s> Eq for Data<'s>

Source§

impl<'s> StructuralPartialEq for Data<'s>

Auto Trait Implementations§

§

impl<'s> !Freeze for Data<'s>

§

impl<'s> RefUnwindSafe for Data<'s>

§

impl<'s> Send for Data<'s>

§

impl<'s> Sync for Data<'s>

§

impl<'s> Unpin for Data<'s>

§

impl<'s> UnwindSafe for Data<'s>

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> Same for T

Source§

type Output = T

Should always be Self
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, 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

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

Source§

impl<T> ErasedDestructor for T
where T: 'static,