pub enum ValueFormat {
Raw,
Pretty,
Both,
}Expand description
Value format for API responses
Controls how FormattedValue<T> fields are serialized in responses.
This allows API consumers to choose between raw numeric values,
human-readable formatted strings, or both.
Variants§
Raw
Return only raw numeric values (e.g., 123.45) - default
Best for programmatic use, calculations, charts
Pretty
Return only formatted strings (e.g., "$123.45", "1.2B")
Best for display purposes
Both
Return both raw and formatted values
Returns the full {raw, fmt, longFmt} object
Implementations§
Source§impl ValueFormat
impl ValueFormat
Sourcepub fn parse(s: &str) -> Option<Self>
pub fn parse(s: &str) -> Option<Self>
Parse from string (case-insensitive), returns None on invalid input
Sourcepub fn transform(&self, value: Value) -> Value
pub fn transform(&self, value: Value) -> Value
Transform a JSON value based on this format
Recursively processes the JSON, detecting FormattedValue objects
(objects with raw key and optionally fmt/longFmt) and
transforming them according to the format setting.
§Example
use finance_query::ValueFormat;
use serde_json::json;
let data = json!({"price": {"raw": 123.45, "fmt": "$123.45"}});
// Raw format extracts just the raw value (default)
let raw = ValueFormat::default().transform(data.clone());
assert_eq!(raw, json!({"price": 123.45}));
// Pretty extracts just the formatted string
let pretty = ValueFormat::Pretty.transform(data.clone());
assert_eq!(pretty, json!({"price": "$123.45"}));
// Both keeps the full object
let both = ValueFormat::Both.transform(data);
assert_eq!(both, json!({"price": {"raw": 123.45, "fmt": "$123.45"}}));Trait Implementations§
Source§impl Clone for ValueFormat
impl Clone for ValueFormat
Source§fn clone(&self) -> ValueFormat
fn clone(&self) -> ValueFormat
Returns a duplicate of the value. Read more
1.0.0 · 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 ValueFormat
impl Debug for ValueFormat
Source§impl Default for ValueFormat
impl Default for ValueFormat
Source§fn default() -> ValueFormat
fn default() -> ValueFormat
Returns the “default value” for a type. Read more
Source§impl FromStr for ValueFormat
impl FromStr for ValueFormat
Source§impl Hash for ValueFormat
impl Hash for ValueFormat
Source§impl PartialEq for ValueFormat
impl PartialEq for ValueFormat
impl Copy for ValueFormat
impl Eq for ValueFormat
impl StructuralPartialEq for ValueFormat
Auto Trait Implementations§
impl Freeze for ValueFormat
impl RefUnwindSafe for ValueFormat
impl Send for ValueFormat
impl Sync for ValueFormat
impl Unpin for ValueFormat
impl UnwindSafe for ValueFormat
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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
Compare self to
key and return true if they are equal.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> 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> ⓘ
Converts
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> ⓘ
Converts
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 more