diff --git a/CHANGELOG.md b/CHANGELOG.md index c1dd21d..0eae605 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - Added `from_zstd` function to `AsyncDbnEncoder` to match synchronous encoder - Added re-exports for `enums::rtype`, `record::BidAskPair`, `record::RecordHeader`, and `record::WithTsOut` to simplify imports +- Added `serde::Deserialize` implementations for `Dataset`, `Venue`, and `Publisher` ### Breaking changes - Changed `Default` implementation for `BidAskPair` by setting prices to `UNDEF_PRICE` diff --git a/rust/dbn/src/publishers.rs b/rust/dbn/src/publishers.rs index 29861ad..e458210 100644 --- a/rust/dbn/src/publishers.rs +++ b/rust/dbn/src/publishers.rs @@ -791,3 +791,39 @@ impl std::str::FromStr for Publisher { } } } + +#[cfg(feature = "serde")] +mod deserialize { + use std::str::FromStr; + + use serde::{de, Deserialize, Deserializer}; + + use super::*; + + impl<'de> Deserialize<'de> for Venue { + fn deserialize>( + deserializer: D, + ) -> std::result::Result { + let str = String::deserialize(deserializer)?; + FromStr::from_str(&str).map_err(de::Error::custom) + } + } + + impl<'de> Deserialize<'de> for Dataset { + fn deserialize>( + deserializer: D, + ) -> std::result::Result { + let str = String::deserialize(deserializer)?; + FromStr::from_str(&str).map_err(de::Error::custom) + } + } + + impl<'de> Deserialize<'de> for Publisher { + fn deserialize>( + deserializer: D, + ) -> std::result::Result { + let str = String::deserialize(deserializer)?; + FromStr::from_str(&str).map_err(de::Error::custom) + } + } +}