Skip to main content

Value

Enum Value 

Source
#[non_exhaustive]
pub enum Value { Null, Bool(bool), Integer(i64), Unsigned(u64), Float(f64), String(String), Bytes(Vec<u8>), Array(Vec<Value>), Map(BTreeMap<String, Value>), }
Expand description

A tree-shaped value that can be read from or written to a Store.

This is the universal data representation in StructFS. It maps directly to JSON, MessagePack, CBOR, etc., but is encoding-agnostic.

§Design Notes

  • Uses BTreeMap for deterministic UTF-8 key ordering
  • Includes Bytes for binary data (unlike JSON, but like CBOR/MessagePack)
  • Integers cover the union of i64 and u64; signedness is not semantic

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Null

A present null value. Distinct from “path doesn’t exist”.

§

Bool(bool)

Boolean value.

§

Integer(i64)

Signed 64-bit integer.

§

Unsigned(u64)

Nonnegative integer storage; normalized values use this only above i64::MAX.

§

Float(f64)

64-bit floating point.

§

String(String)

UTF-8 string.

§

Bytes(Vec<u8>)

Binary data (for formats that support it: CBOR, MessagePack, etc.)

§

Array(Vec<Value>)

Ordered sequence of values.

§

Map(BTreeMap<String, Value>)

Key-value map with string keys (the “struct” part).

Implementations§

Source§

impl Value

Source

pub fn normalize(&mut self)

Normalize signedness and NaNs recursively. Ordinary PartialEq is unchanged.

Source

pub fn semantic_eq(&self, other: &Value) -> bool

Equality defined by StructFS Value v1, including NaN equality and signed zero.

Source

pub fn null() -> Value

Create a null value.

Source

pub fn map() -> Value

Create an empty map.

Source

pub fn array() -> Value

Create an empty array.

Source

pub fn is_null(&self) -> bool

Check if this value is null.

Source

pub fn is_map(&self) -> bool

Check if this value is a map (struct).

Source

pub fn is_array(&self) -> bool

Check if this value is an array.

Source

pub fn get(&self, path: &Path) -> Option<&Value>

Get a reference to a nested value by path.

Returns None if the path doesn’t exist or can’t be navigated (e.g., trying to index into a string).

Source

pub fn get_mut(&mut self, path: &Path) -> Option<&mut Value>

Get a mutable reference to a nested value by path.

Source

pub fn set(&mut self, path: &Path, value: Value) -> Result<(), Error>

Set a value at a path, creating intermediate maps as needed.

§Errors

Returns an error if the path traverses through a non-container value (e.g., trying to set foo/bar when foo is a string).

Source

pub fn remove(&mut self, path: &Path) -> Result<Option<Value>, Error>

Remove a value at a path, returning it if it existed.

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Value

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Value

Source§

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

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

impl Default for Value

Source§

fn default() -> Value

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Value

Source§

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

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<&str> for Value

Source§

fn from(v: &str) -> Value

Converts to this type from the input type.
Source§

impl From<String> for Value

Source§

fn from(v: String) -> Value

Converts to this type from the input type.
Source§

impl From<Value> for Record

Source§

fn from(v: Value) -> Record

Converts to this type from the input type.
Source§

impl<T> From<Vec<T>> for Value
where T: Into<Value>,

Source§

fn from(v: Vec<T>) -> Value

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for Value

Source§

fn from(v: Vec<u8>) -> Value

Converts to this type from the input type.
Source§

impl From<bool> for Value

Source§

fn from(v: bool) -> Value

Converts to this type from the input type.
Source§

impl From<f64> for Value

Source§

fn from(v: f64) -> Value

Converts to this type from the input type.
Source§

impl From<i32> for Value

Source§

fn from(v: i32) -> Value

Converts to this type from the input type.
Source§

impl From<i64> for Value

Source§

fn from(v: i64) -> Value

Converts to this type from the input type.
Source§

impl From<u64> for Value

Source§

fn from(v: u64) -> Value

Converts to this type from the input type.
Source§

impl PartialEq for Value

Source§

fn eq(&self, other: &Value) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Value

Source§

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

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

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> 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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.