pub enum Value {
Null,
Bool(bool),
Int(i64),
Float(f64),
Str(Cow<'static, str>),
Dict(Arc<IndexMap<String, Value>>),
Arr(Arc<Vec<Value>>),
}Expand description
A dynamic value type that mirrors the CCXT JavaScript Value semantics.
Dict/Arr hold their containers behind an Arc so that clone() is
an O(1) refcount bump instead of a deep copy — the transpiled parsers
and the static-test assertions clone Values pervasively (every
safeString/safeNumber, every recursion level), which dominated
runtime. Mutation goes through Arc::make_mut (copy-on-write): it
only deep-copies when the container is actually shared.
NOTE: the variants are named Dict/Arr, but construction uses the
associated functions Value::Map(..) / Value::Array(..) /
Value::List(..) (which wrap the Arc) so the ~18k transpiler-emitted
Value::Map({..}) / Value::List(vec![..]) call sites need no change.
Pattern matches use Value::Dict(..) / Value::Arr(..).
Str holds a Cow<'static, str>: transpiler-emitted string literals
borrow their &'static str (Value::Str("lit".into()), zero allocation)
while runtime-built strings stay owned. clone() on a borrowed literal
is a pointer copy.
Variants§
Null
Bool(bool)
Int(i64)
Float(f64)
Str(Cow<'static, str>)
Dict(Arc<IndexMap<String, Value>>)
Arr(Arc<Vec<Value>>)
Implementations§
Source§impl Value
impl Value
Sourcepub fn reduce(&mut self)
pub fn reduce(&mut self)
Mirrors TS Precise.reduce(): when this Value is a
Precise::new(...) Map (carries the __precise marker), strip
trailing zeros from integer and bump decimals down to match.
Used by phemex’s to_en after it shifts decimals by the
market’s valueScale: subtracts decimals, then reduce balances
the integer side so the final stringify_param renders the
scaled integer correctly (0.1 × 10^8 → 10000000).
Sourcepub fn append(&mut self, item: Value)
pub fn append(&mut self, item: Value)
append(item) on an Array — pushes the item. Mirrors TS
array.push shape (single arg, no return).
On a WS-cache Map (carrying a __cacheKind marker; see
crate::pro::cache) it dispatches to the per-kind logic below.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
clear() — resets the rolling buffer for a cache marker (or
truncates the inner array of an Arr value).
Sourcepub fn get_limit(&mut self, symbol: Value, limit: Value) -> Value
pub fn get_limit(&mut self, symbol: Value, limit: Value) -> Value
getLimit(symbol, limit) for the cache markers. Returns the
count of new updates since the last call (clamped by limit
when supplied) and arms the per-symbol / global reset flag so
the next append zeroes the counter.
Sourcepub fn List(items: Vec<Value>) -> Value
pub fn List(items: Vec<Value>) -> Value
Constructor named to match the ast-transpiler’s emission shape:
Value::List(vec![...]). Aliases Value::Array. Note that this
is a function, not a variant — so pattern matches still use
Value::Array(_), not Value::List(_).
Sourcepub fn Map(m: IndexMap<String, Value>) -> Value
pub fn Map(m: IndexMap<String, Value>) -> Value
Construction shim — the transpiler emits Value::Map({..IndexMap..})
in ~18k places; this wraps the map in the Arc the Dict variant
now holds. (An associated fn, not a variant — patterns use Dict.)
pub fn str(s: impl Into<String>) -> Value
pub fn int(n: i64) -> Value
pub fn float(f: f64) -> Value
pub fn bool(b: bool) -> Value
pub fn map(m: IndexMap<String, Value>) -> Value
pub fn array(a: Vec<Value>) -> Value
pub fn is_null(&self) -> bool
pub fn is_str(&self) -> bool
pub fn is_int(&self) -> bool
pub fn is_float(&self) -> bool
pub fn is_number(&self) -> bool
pub fn is_bool(&self) -> bool
pub fn is_map(&self) -> bool
pub fn is_array(&self) -> bool
pub fn is_truthy(&self) -> bool
pub fn as_str(&self) -> Option<&str>
pub fn as_i64(&self) -> Option<i64>
pub fn as_f64(&self) -> Option<f64>
pub fn as_bool(&self) -> Option<bool>
pub fn as_map(&self) -> Option<&IndexMap<String, Value>>
pub fn as_array(&self) -> Option<&Vec<Value>>
Sourcepub fn to_str_vec(&self) -> Vec<String>
pub fn to_str_vec(&self) -> Vec<String>
Display text of each array element (empty for a non-array); the Vec<String> dispatch bridge.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Length of array, map, or string; 0 for everything else.
String length counts Unicode chars (matches TS String#length
closely enough for ASCII-only API addresses/identifiers).
pub fn is_empty(&self) -> bool
pub fn describe(&self) -> Value
Sourcepub fn reject(&self, args: &[Value]) -> Value
pub fn reject(&self, args: &[Value]) -> Value
client.reject(error, messageHash) — stores a rejection the watch
drive loop delivers to the awaiting caller. Routes by the client
handle’s url to the WS registry (no-op on a non-client Value).
Sourcepub fn resolve(&self, args: &[Value]) -> Value
pub fn resolve(&self, args: &[Value]) -> Value
client.resolve(value, messageHash) — stores the resolved value the
watch drive loop returns. Routes by the client handle’s url.
Sourcepub fn future(&self, args: &[Value]) -> Value
pub fn future(&self, args: &[Value]) -> Value
client.future(messageHash) — TS’s atomic check-and-insert: opens a
single-flight for the hash (or joins the open one) and hands back a
handle. Registering is the whole point — it is what makes a concurrent
caller’s messageHash in client.futures test true, so only one of them
does the work (venue authenticate leader election). Await the handle
with exchange_stubs::ws_await_flight; the transpiler emits that
wherever the TS source awaits.
Sourcepub fn reusable_future(&self, msg_hash: Value) -> Value
pub fn reusable_future(&self, msg_hash: Value) -> Value
client.reusable_future(messageHash) — shared flight per hash, i.e. the
same registry and handle as future.
Sourcepub fn hashmap(&self) -> Value
pub fn hashmap(&self) -> Value
Field accessor: cache.hashmap — same as the WS Cache marker’s
hashmap sub-dict. Some transpiled WS code reads this directly
via the JS field-access syntax rather than going through
get_value.
Sourcepub fn send(&self, args: &[Value]) -> Value
pub fn send(&self, args: &[Value]) -> Value
client.send(payload) — queues a frame on the WS connection (routed by
the client handle’s url). No-op on a non-client Value.
Sourcepub fn decode_proto_msg(&self, _args: &[Value]) -> Value
pub fn decode_proto_msg(&self, _args: &[Value]) -> Value
client.decode_proto_msg(...) — exchange-specific protobuf
decode helper; stubbed to Value::Null.
Sourcepub fn on_pong(&self, _args: &[Value]) -> Value
pub fn on_pong(&self, _args: &[Value]) -> Value
client.on_pong(...) — WS heartbeat hook; records the pong time.
Sourcepub fn call(&self, _args: &[Value]) -> Value
pub fn call(&self, _args: &[Value]) -> Value
WS stub — transpiled fn(...args) over a Value-typed callable.
Sourcepub fn is_dictionary(&self, value: Value) -> Value
pub fn is_dictionary(&self, value: Value) -> Value
exchange.isDictionary(value) — transpiled tests treat exchange
as Value instead of the typed Exchange, so we mirror the
dict-typecheck method here.
Sourcepub fn network_code_to_id(&self, code: Value, args: &[Value]) -> Value
pub fn network_code_to_id(&self, code: Value, args: &[Value]) -> Value
exchange.networkCodeToId(code, currency) on a snapshot Value —
delegates to the transpiled Exchange::network_code_to_id.
Sourcepub fn network_id_to_code(&self, args: &[Value]) -> Value
pub fn network_id_to_code(&self, args: &[Value]) -> Value
exchange.networkIdToCode(networkId, currency) on a snapshot Value
— delegates to the transpiled Exchange::network_id_to_code.
Sourcepub fn extend(&self, a: Value, args: &[Value]) -> Value
pub fn extend(&self, a: Value, args: &[Value]) -> Value
exchange.extend(a, b, ...) on a snapshot Value — CCXT’s shallow
object merge. Pure (ignores exchange state), so it delegates to the
transpiled Exchange::extend. Used by the (prediction-aware) transpiled
test harness, where exchange is a dynamic Value handle.
Sourcepub fn set_markets(&mut self, markets: Value) -> Value
pub fn set_markets(&mut self, markets: Value) -> Value
exchange.setMarkets(markets) on a snapshot Value — used by the
prediction test harness to seed event-derived markets. Delegates the
indexing to the transpiled Exchange::set_markets, then writes the
computed markets/markets_by_id/symbols back onto the Value
handle so later get_value(exchange, "markets") reads see them.
Sourcepub fn store_array(&mut self, delta: Value)
pub fn store_array(&mut self, delta: Value)
side.storeArray(delta) — insert/update/delete by price (or
by id for the indexed variant). Defined here (rather than next
to store) so that derived exchange code which calls
Value::store_array on a non-side Value still compiles as a
no-op.
pub fn append_to_array(&self, _v: Value)
pub fn to_json(&self) -> Value
pub fn from_json(v: &Value) -> Value
Source§impl Value
impl Value
Sourcepub fn set_book_meta(&mut self, k: &str, v: Value)
pub fn set_book_meta(&mut self, k: &str, v: Value)
book.timestamp|datetime|nonce|symbol = v — the shared-store write for a
tagged book, else the generic element write (same result as the helper).
Sourcepub fn book_field(&self, k: &str) -> Value
pub fn book_field(&self, k: &str) -> Value
book['bids'|'asks'|'nonce'|...] read on an order-book-typed local: the same
shared-store lookup get_value does for these keys, without the boxed key.
Sourcepub fn limit(&mut self) -> Value
pub fn limit(&mut self) -> Value
book.limit() — trim both sides to _depth. Returns a clone
of self so transpiled return book.limit(); lines still
match the -> Value signature.
Sourcepub fn reset(&mut self, snapshot: Value) -> Value
pub fn reset(&mut self, snapshot: Value) -> Value
book.reset(snapshot) — wipe + reseed bids/asks + metadata.
Returns self for the same reason as limit(). A bare
book.reset() is also valid (matches the TS OrderBook shape);
when called without a snapshot, we just rebind the existing one
(effectively a no-op metadata refresh).
Sourcepub fn reset0(&mut self) -> Value
pub fn reset0(&mut self) -> Value
Zero-arg reset() form used by per-exchange WS code that just
wants to clear the rolling buffers.
Sourcepub fn update(&mut self, snapshot: Value) -> Value
pub fn update(&mut self, snapshot: Value) -> Value
book.update(snapshot) — same as reset but only when the
supplied nonce moves forward.
Sourcepub fn store(&mut self, price: Value, size: Value)
pub fn store(&mut self, price: Value, size: Value)
side.store(price, size) — convenience that builds a 2-element
delta. Routed through the side’s store_array. Only useful on a
side marker (returned by book['bids']), not the book itself.
Sourcepub fn store_to_bids(&mut self, price: Value, size: Value)
pub fn store_to_bids(&mut self, price: Value, size: Value)
Book-level side mutators — the transpiler rewrites side-extraction
patterns (let bids = book['bids']; bids.X(...)) into calls on
these methods so the mutation reaches the book’s actual side
dict rather than a COW-cloned copy of it.
pub fn store_to_asks(&mut self, price: Value, size: Value)
pub fn store_array_to_bids(&mut self, delta: Value)
pub fn store_array_to_asks(&mut self, delta: Value)
Trait Implementations§
Source§impl From<ExchangeError> for Value
From<ExchangeError> makes error.clone() flow into &[Value]
slices without an explicit conversion — surfaces the typed error
as a [Kind] message-shaped string Value, matching how
runtime::panic_msg_to_error round-trips it back into a typed
ExchangeError for the caller.
impl From<ExchangeError> for Value
From<ExchangeError> makes error.clone() flow into &[Value]
slices without an explicit conversion — surfaces the typed error
as a [Kind] message-shaped string Value, matching how
runtime::panic_msg_to_error round-trips it back into a typed
ExchangeError for the caller.
Source§fn from(e: ExchangeError) -> Value
fn from(e: ExchangeError) -> Value
Source§impl From<Value> for Params
Back-compat: existing call sites that already hold a Value (including
Value::Null) keep working without a conversion at the call site.
impl From<Value> for Params
Back-compat: existing call sites that already hold a Value (including
Value::Null) keep working without a conversion at the call site.