Skip to main content

NxValue

Enum NxValue 

Source
pub enum NxValue {
    Bool(bool),
    Int32(i32),
    Int(i64),
    Float32(f32),
    Float(f64),
    String(String),
    Null,
    Array(Vec<NxValue>),
    Record {
        type_name: Option<String>,
        properties: BTreeMap<String, NxValue>,
    },
}
Expand description

A JSON-like tree value used as the stable NX API value type.

It is the Rust form of a canonical value, which docs/nx-ir-format.md (Host values) defines: a host builds one and passes it as it is, whether it read the value from JSON or computed it, and JSON and MessagePack are encodings of it for a wire or a store. It can hold nothing that is not a canonical value, so a runtime given one has nothing to refuse for its kind.

Constant union cases are represented as NxValue::String carrying the bare authored case name. The declaring union is recovered from the target schema (declared NX type, typed DTO property, or other type annotation) at the point where the value is consumed; the IR itself carries no in-payload union type wrapper.

NX has no null: its absent value is the empty sequence, NxValue::empty. NxValue::Null is the host’s spelling of absence, which NX reads as the empty value. NX writes it in two places: an entry call’s result whose type is a standalone T? and holds nothing, and a present empty field of an update record — a cleared field — which is how key presence carries “cleared” through JSON. An absent optional record field is an omitted key.

Variants§

§

Bool(bool)

§

Int32(i32)

§

Int(i64)

§

Float32(f32)

§

Float(f64)

§

String(String)

String value.

A string value may represent either a plain string or a constant union case. The two are distinguishable only against the target schema — a schema-less consumer cannot tell them apart from the payload alone.

§

Null

The host’s null: JSON null, MessagePack nil. NX reads it as the empty value.

§

Array(Vec<NxValue>)

§

Record

Record value (ordered properties).

When serialized to JSON, type_name is encoded as a "$type" string property if present.

Fields

§type_name: Option<String>
§properties: BTreeMap<String, NxValue>

Implementations§

Source§

impl NxValue

Source

pub fn empty() -> Self

The empty value: the empty sequence, which is also the absent value.

Source

pub fn is_empty_value(&self) -> bool

True for the empty value, or for a host null, which NX reads as the empty value.

Source

pub fn from_json_str(source: &str) -> Result<Self, Error>

Deserialize a value from a JSON string.

Source

pub fn from_json_reader<R: Read>(reader: R) -> Result<Self, Error>

Deserialize a value from a JSON reader.

Source

pub fn from_json_file(path: impl AsRef<Path>) -> Result<Self, NxValueIoError>

Deserialize a value from a JSON file.

Source

pub fn to_json_string(&self) -> Result<String, Error>

Serialize a value to a compact JSON string.

Source

pub fn to_json_string_pretty(&self) -> Result<String, Error>

Serialize a value to a pretty JSON string.

Source

pub fn to_json_writer<W: Write>(&self, writer: W) -> Result<(), Error>

Serialize a value to JSON using the provided writer.

Source

pub fn to_json_file(&self, path: impl AsRef<Path>) -> Result<(), NxValueIoError>

Serialize a value to a JSON file (compact form).

Source

pub fn to_json_file_pretty( &self, path: impl AsRef<Path>, ) -> Result<(), NxValueIoError>

Serialize a value to a JSON file (pretty form).

Source

pub fn to_msgpack_vec(&self) -> Result<Vec<u8>, Error>

Serialize a value to MessagePack bytes.

Source

pub fn from_msgpack_slice(bytes: &[u8]) -> Result<Self, Error>

Deserialize a value from MessagePack bytes.

Trait Implementations§

Source§

impl Clone for NxValue

Source§

fn clone(&self) -> Self

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 NxValue

Source§

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

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

impl<'de> Deserialize<'de> for NxValue

Source§

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

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

impl PartialEq for NxValue

Source§

fn eq(&self, other: &Self) -> 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 NxValue

Source§

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

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

impl StructuralPartialEq for NxValue

Auto Trait Implementations§

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.