pub struct NumberString(/* private fields */);Expand description
A numeric value returned by OKX as a JSON string.
OKX encodes all prices, sizes, and balances as strings to avoid floating
point precision loss. NumberString preserves the exact wire representation
and lets the caller decide how to interpret it:
use rust_okx::NumberString;
let px = NumberString::from("42000.1");
assert_eq!(px.as_str(), "42000.1");
let as_f64: f64 = px.parse()?;
assert_eq!(as_f64, 42000.1);Implementations§
Source§impl NumberString
impl NumberString
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the value is the empty string (OKX uses "" for
“not applicable” fields).
Sourcepub fn parse<T: FromStr>(&self) -> Result<T, T::Err>
pub fn parse<T: FromStr>(&self) -> Result<T, T::Err>
Parse the value into any FromStr type, e.g. f64, i64, or
rust_decimal::Decimal.
Sourcepub fn into_string(self) -> String
pub fn into_string(self) -> String
Consume the wrapper and return the inner String.
Sourcepub fn to_decimal(&self) -> Result<Decimal, Error>
pub fn to_decimal(&self) -> Result<Decimal, Error>
Parse the value as a rust_decimal::Decimal.
Trait Implementations§
Source§impl AsRef<str> for NumberString
impl AsRef<str> for NumberString
Source§impl Clone for NumberString
impl Clone for NumberString
Source§fn clone(&self) -> NumberString
fn clone(&self) -> NumberString
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for NumberString
impl Debug for NumberString
Source§impl Default for NumberString
impl Default for NumberString
Source§fn default() -> NumberString
fn default() -> NumberString
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for NumberString
impl<'de> Deserialize<'de> for NumberString
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>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Display for NumberString
impl Display for NumberString
impl Eq for NumberString
Source§impl From<&str> for NumberString
impl From<&str> for NumberString
Source§impl From<String> for NumberString
impl From<String> for NumberString
Source§impl Hash for NumberString
impl Hash for NumberString
Source§impl PartialEq for NumberString
impl PartialEq for NumberString
Source§impl Serialize for NumberString
impl Serialize for NumberString
impl StructuralPartialEq for NumberString
Auto Trait Implementations§
impl Freeze for NumberString
impl RefUnwindSafe for NumberString
impl Send for NumberString
impl Sync for NumberString
impl Unpin for NumberString
impl UnsafeUnpin for NumberString
impl UnwindSafe for NumberString
Blanket Implementations§
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
Mutably borrows from an owned value. Read more