#[non_exhaustive]pub enum ParseError {
Decimal(Error),
Json(Error),
Timestamp(Cow<'static, str>),
MissingField(Cow<'static, str>),
InvalidValue {
field: Cow<'static, str>,
message: Cow<'static, str>,
},
InvalidFormat {
field: Cow<'static, str>,
message: Cow<'static, str>,
},
}Expand description
Errors related to parsing exchange responses.
This type handles all parsing failures including JSON deserialization, decimal number parsing, timestamp parsing, and missing/invalid fields.
§Memory Optimization
Uses Cow<'static, str> for field names and messages to avoid allocation
when using static strings. Use the helper constructors for ergonomic creation:
use ccxt_core::error::ParseError;
// Zero allocation (static string)
let err = ParseError::missing_field("price");
// Allocation only when needed (dynamic string)
let field_name = format!("field_{}", 42);
let err = ParseError::missing_field_owned(field_name);
// Invalid value with context
let err = ParseError::invalid_value("amount", "must be positive");§Example
use ccxt_core::error::{Error, ParseError, Result};
fn parse_price(json: &serde_json::Value) -> Result<f64> {
json.get("price")
.and_then(|v| v.as_f64())
.ok_or_else(|| Error::from(ParseError::missing_field("price")))
}Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Decimal(Error)
Failed to parse decimal number.
Json(Error)
Failed to deserialize JSON.
Timestamp(Cow<'static, str>)
Failed to parse timestamp.
MissingField(Cow<'static, str>)
Missing required field in response.
InvalidValue
Invalid value for a field.
InvalidFormat
Invalid format for a field.
Implementations§
Source§impl ParseError
impl ParseError
Sourcepub fn missing_field(field: &'static str) -> Self
pub fn missing_field(field: &'static str) -> Self
Creates a MissingField error with a static string (no allocation).
Sourcepub fn missing_field_owned(field: String) -> Self
pub fn missing_field_owned(field: String) -> Self
Creates a MissingField error with a dynamic string.
Sourcepub fn invalid_value(
field: impl Into<Cow<'static, str>>,
message: impl Into<Cow<'static, str>>,
) -> Self
pub fn invalid_value( field: impl Into<Cow<'static, str>>, message: impl Into<Cow<'static, str>>, ) -> Self
Creates an InvalidValue error.
Sourcepub fn timestamp(message: &'static str) -> Self
pub fn timestamp(message: &'static str) -> Self
Creates a Timestamp error with a static string (no allocation).
Sourcepub fn timestamp_owned(message: String) -> Self
pub fn timestamp_owned(message: String) -> Self
Creates a Timestamp error with a dynamic string.
Trait Implementations§
Source§impl Debug for ParseError
impl Debug for ParseError
Source§impl Display for ParseError
impl Display for ParseError
Source§impl Error for ParseError
impl Error for ParseError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
Source§impl From<Error> for ParseError
impl From<Error> for ParseError
Source§impl From<Error> for ParseError
impl From<Error> for ParseError
Source§impl From<ParseError> for Error
impl From<ParseError> for Error
Source§fn from(e: ParseError) -> Self
fn from(e: ParseError) -> Self
Auto Trait Implementations§
impl Freeze for ParseError
impl !RefUnwindSafe for ParseError
impl Send for ParseError
impl Sync for ParseError
impl Unpin for ParseError
impl !UnwindSafe for ParseError
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.