pub enum MetaValueJson {
String(String),
Bool(bool),
Amount {
number: String,
currency: String,
},
Null,
}Expand description
Metadata-value wire format for WASM consumers.
JSON output is byte-equivalent to FFI-WASI’s
meta_value_to_json — JS clients writing portable code see
identical metadata values from both bindings. The Rust-side
types are independent though: FFI-WASI emits
serde_json::Value (untyped), this crate emits a typed enum.
Unifying the source-of-truth is tracked by issue #1200 item 2.
The host’s rustledger_core::MetaValue is richer than the wire
type — Account/Currency/Tag/Link/Date/Number all
flatten to JSON strings here, matching FFI-WASI behavior. JS
consumers that need the strong type info should query the host
via a typed API; this enum is the lossy-but-portable view.
Untagged on the wire: "hello" serializes as a string,
true as a boolean, null as null, and an AmountValue
{number,currency} as a plain object. The TypeScript union is
Record<string, string | boolean | {number, currency} | null> —
no raw JSON number arm because MetaValue::Number (Decimal)
stringifies to preserve precision. Issue #1168 proposed
string | number | boolean | null; we substitute the
{number,currency} shape for number so cost-bearing metadata
round-trips cleanly and so JS numeric literals don’t silently
alias into the wire (see the meta_value_json_rejects_raw_json_number
test).
Variants§
String(String)
String/Account/Currency/Tag/Link/Date/Number — anything the
host can represent as a string, including rust_decimal::Decimal
values stringified to preserve precision (JSON numbers can’t
represent arbitrary-precision decimals losslessly).
Bool(bool)
Boolean values.
Amount
Amount values ({number, currency}) — the only structured
shape that survives the round-trip. Same {number, currency}
envelope as AmountValue so JS consumers can branch on
shape without a discriminator tag.
Deserialize note: serde’s untagged-enum matcher accepts
extra fields in a JSON object (#[serde(deny_unknown_fields)]
can’t be applied per-variant on an untagged enum without
breaking the wider match). A JS client sending
{number: "100", currency: "USD", extra: "x"} deserializes as
Amount { number: "100", currency: "USD" } with extra
silently dropped. Output-side consumers (the production path)
are unaffected; treat Deserialize here as best-effort and
validate at the host boundary if you need stricter checks.
Fields
Null
Absent / null metadata value. Deserializes from JSON null;
serializes to JSON null. (Serde supports unit variants in
untagged enums for null values specifically — a less common
pattern than struct/tuple variants but well-defined.)
Trait Implementations§
Source§impl Clone for MetaValueJson
impl Clone for MetaValueJson
Source§fn clone(&self) -> MetaValueJson
fn clone(&self) -> MetaValueJson
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MetaValueJson
impl Debug for MetaValueJson
Source§impl<'de> Deserialize<'de> for MetaValueJson
impl<'de> Deserialize<'de> for MetaValueJson
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for MetaValueJson
Source§impl PartialEq for MetaValueJson
impl PartialEq for MetaValueJson
Source§impl Serialize for MetaValueJson
impl Serialize for MetaValueJson
impl StructuralPartialEq for MetaValueJson
Auto Trait Implementations§
impl Freeze for MetaValueJson
impl RefUnwindSafe for MetaValueJson
impl Send for MetaValueJson
impl Sync for MetaValueJson
impl Unpin for MetaValueJson
impl UnsafeUnpin for MetaValueJson
impl UnwindSafe for MetaValueJson
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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 moreSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.