Skip to content

Commit

Permalink
ADD: Add Deserialize for publisher enums
Browse files Browse the repository at this point in the history
  • Loading branch information
threecgreen committed Oct 10, 2023
1 parent 5c3261d commit d300b3e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
36 changes: 36 additions & 0 deletions rust/dbn/src/publishers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<D: Deserializer<'de>>(
deserializer: D,
) -> std::result::Result<Self, D::Error> {
let str = String::deserialize(deserializer)?;
FromStr::from_str(&str).map_err(de::Error::custom)
}
}

impl<'de> Deserialize<'de> for Dataset {
fn deserialize<D: Deserializer<'de>>(
deserializer: D,
) -> std::result::Result<Self, D::Error> {
let str = String::deserialize(deserializer)?;
FromStr::from_str(&str).map_err(de::Error::custom)
}
}

impl<'de> Deserialize<'de> for Publisher {
fn deserialize<D: Deserializer<'de>>(
deserializer: D,
) -> std::result::Result<Self, D::Error> {
let str = String::deserialize(deserializer)?;
FromStr::from_str(&str).map_err(de::Error::custom)
}
}
}

0 comments on commit d300b3e

Please sign in to comment.