Skip to main content

Value

Enum Value 

Source
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

Source

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).

Source

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.

Source

pub fn clear(&mut self)

clear() — resets the rolling buffer for a cache marker (or truncates the inner array of an Arr value).

Source

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.

Source

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(_).

Source

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.)

Source

pub fn Array(a: Vec<Value>) -> Value

Construction shim for Value::Array(vec) call sites.

Source

pub fn str(s: impl Into<String>) -> Value

Source

pub fn int(n: i64) -> Value

Source

pub fn float(f: f64) -> Value

Source

pub fn bool(b: bool) -> Value

Source

pub fn map(m: IndexMap<String, Value>) -> Value

Source

pub fn array(a: Vec<Value>) -> Value

Source

pub fn is_null(&self) -> bool

Source

pub fn is_str(&self) -> bool

Source

pub fn is_int(&self) -> bool

Source

pub fn is_float(&self) -> bool

Source

pub fn is_number(&self) -> bool

Source

pub fn is_bool(&self) -> bool

Source

pub fn is_map(&self) -> bool

Source

pub fn is_array(&self) -> bool

Source

pub fn is_truthy(&self) -> bool

Source

pub fn as_str(&self) -> Option<&str>

Source

pub fn as_i64(&self) -> Option<i64>

Source

pub fn as_f64(&self) -> Option<f64>

Source

pub fn as_bool(&self) -> Option<bool>

Source

pub fn as_map(&self) -> Option<&IndexMap<String, Value>>

Source

pub fn as_array(&self) -> Option<&Vec<Value>>

Source

pub fn to_str_vec(&self) -> Vec<String>

Display text of each array element (empty for a non-array); the Vec<String> dispatch bridge.

Source

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).

Source

pub fn is_empty(&self) -> bool

Source

pub fn describe(&self) -> Value

Source

pub fn url(&self) -> Value

client.url on a ws client handle (Value::Null on any other Value).

Source

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).

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn decode_proto_msg(&self, _args: &[Value]) -> Value

client.decode_proto_msg(...) — exchange-specific protobuf decode helper; stubbed to Value::Null.

Source

pub fn on_pong(&self, _args: &[Value]) -> Value

client.on_pong(...) — WS heartbeat hook; records the pong time.

Source

pub fn call(&self, _args: &[Value]) -> Value

WS stub — transpiled fn(...args) over a Value-typed callable.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn append_to_array(&self, _v: Value)

Source

pub fn to_json(&self) -> Value

Source

pub fn from_json(v: &Value) -> Value

Source§

impl Value

Source

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).

Source

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.

Source

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.

Source

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).

Source

pub fn reset0(&mut self) -> Value

Zero-arg reset() form used by per-exchange WS code that just wants to clear the rolling buffers.

Source

pub fn update(&mut self, snapshot: Value) -> Value

book.update(snapshot) — same as reset but only when the supplied nonce moves forward.

Source

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.

Source

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.

Source

pub fn store_to_asks(&mut self, price: Value, size: Value)

Source

pub fn store_array_to_bids(&mut self, delta: Value)

Source

pub fn store_array_to_asks(&mut self, delta: Value)

Trait Implementations§

Source§

impl BitAnd for Value

Source§

type Output = Value

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: Value) -> Value

Performs the & operation. Read more
Source§

impl BitOr for Value

Source§

type Output = Value

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Value) -> Value

Performs the | operation. Read more
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 Display for Value

Source§

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

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

impl From<&str> for Value

Source§

fn from(s: &str) -> Value

Converts to this type from the input type.
Source§

impl From<Config> for Value

Source§

fn from(c: Config) -> Value

Converts to this type from the input type.
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.

Source§

fn from(e: ExchangeError) -> Value

Converts to this type from the input type.
Source§

impl From<IndexMap<String, IndexMap<String, Value>>> for Value

Source§

fn from(m: IndexMap<String, IndexMap<String, Value>>) -> Value

Converts to this type from the input type.
Source§

impl From<IndexMap<String, Value>> for Value

Source§

fn from(m: IndexMap<String, Value>) -> Value

Converts to this type from the input type.
Source§

impl From<Option<f64>> for Value

Source§

fn from(n: Option<f64>) -> Value

Converts to this type from the input type.
Source§

impl From<Option<i64>> for Value

Source§

fn from(n: Option<i64>) -> Value

Converts to this type from the input type.
Source§

impl From<Params> for Value

Source§

fn from(p: Params) -> Value

Converts to this type from the input type.
Source§

impl From<String> for Value

Source§

fn from(s: String) -> Value

Converts to this type from the input type.
Source§

impl From<Value> for Value

Source§

fn from(v: Value) -> Value

Converts to this type from the input type.
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.

Source§

fn from(v: Value) -> Params

Converts to this type from the input type.
Source§

impl From<Vec<Value>> for Value

Source§

fn from(a: Vec<Value>) -> Value

Converts to this type from the input type.
Source§

impl From<bool> for Value

Source§

fn from(b: bool) -> Value

Converts to this type from the input type.
Source§

impl From<f64> for Value

Source§

fn from(f: f64) -> Value

Converts to this type from the input type.
Source§

impl From<i64> for Value

Source§

fn from(n: i64) -> Value

Converts to this type from the input type.
Source§

impl IsTruthy for Value

Source§

fn truthy(&self) -> bool

Source§

impl IsTruthy for &Value

Source§

fn truthy(&self) -> bool

Source§

impl Not for Value

Source§

type Output = Value

The resulting type after applying the ! operator.
Source§

fn not(self) -> Value

Performs the unary ! operation using logical or bitwise negation. Read more
Source§

impl Not for &Value

Source§

type Output = Value

The resulting type after applying the ! operator.
Source§

fn not(self) -> Value

Performs the unary ! operation using logical or bitwise negation. Read more
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 StructuralPartialEq for Value

Source§

impl ToErrorMessage for Value

Source§

impl ToErrorMessage for &Value

Auto Trait Implementations§

§

impl Forget for Value

§

impl Freeze for Value

§

impl Move 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more