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.
The aliases mirror the shorthands FromStr accepts, so
deserializing (axum query extraction, JSON) takes the same spellings parsing does.
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
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for ValueFormat
Source§impl Debug for ValueFormat
impl Debug for ValueFormat
Source§impl Default for ValueFormat
impl Default for ValueFormat
Source§fn default() -> ValueFormat
fn default() -> ValueFormat
Source§impl<'de> Deserialize<'de> for ValueFormat
impl<'de> Deserialize<'de> for ValueFormat
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>,
impl Eq for ValueFormat
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
Source§impl Serialize for ValueFormat
impl Serialize 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 UnsafeUnpin 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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
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> ⓘ
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> ⓘ
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