pub enum Value {
Null,
Bool(bool),
Integer(i64),
String(String),
Bytes(Vec<u8>),
Link(Cid),
List(Vec<Value>),
Map(BTreeMap<String, Value>),
}Expand description
A value in the atproto data model.
There is no float variant, and that absence is the point rather than an
omission. A float has several encodings of the same number and no exact
equality, so a record containing one has no single hash; atproto removed
them from the model outright. A JSON number that happens to be written
123.0 is an integer and parses as one, and one that is not is refused.
Variants§
Null
JSON null.
Bool(bool)
A boolean.
Integer(i64)
A signed 64-bit integer, which is the only number the model has.
String(String)
A UTF-8 string.
Bytes(Vec<u8>)
A byte string, written {"$bytes": "..."} in JSON.
Link(Cid)
A link to another block, written {"$link": "..."} in JSON.
List(Vec<Value>)
An ordered list.
Map(BTreeMap<String, Value>)
A map with string keys. Insertion order is not kept, because the encoding defines its own order and nothing else may depend on one.
Implementations§
Source§impl Value
impl Value
Sourcepub fn from_json(json: &Value) -> Result<Self, DataError>
pub fn from_json(json: &Value) -> Result<Self, DataError>
Parses one JSON value into the data model.
use didbot_data::Value;
let json = serde_json::json!({"a": 1, "b": [true, null]});
assert!(Value::from_json(&json).is_ok());
assert!(Value::from_json(&serde_json::json!(1.5)).is_err());Sourcepub fn object_from_json(json: &Value) -> Result<Self, DataError>
pub fn object_from_json(json: &Value) -> Result<Self, DataError>
Parses a JSON value that must be an object, which is what a record is.
The data model permits any value inside a record, but the record
itself — and every block a repository stores — is a map. Upstream’s
first invalid vector is the bare string "blah", so this is a rule
with a test rather than a tidiness.
Trait Implementations§
Source§impl Ord for Value
impl Ord for Value
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Value
impl PartialOrd for Value
impl Eq for Value
impl StructuralPartialEq for Value
Auto Trait Implementations§
impl Freeze for Value
impl RefUnwindSafe for Value
impl Send for Value
impl Sync for Value
impl Unpin for Value
impl UnsafeUnpin for Value
impl UnwindSafe for Value
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<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.