Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove workaround for serde_json's arbitrary_precision feature #1669

Merged
merged 1 commit into from Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -35,7 +35,7 @@ members = [

[dependencies]
bitflags = "1.1"
serde_json = "1"
serde_json = "1.0.75"
async-trait = "0.1.9"

[dependencies.simd-json]
Expand Down
37 changes: 2 additions & 35 deletions src/model/id.rs
Expand Up @@ -253,8 +253,8 @@ id_u64! {
pub(crate) mod snowflake {
use std::fmt;

use serde::de::{Error, MapAccess, Visitor};
use serde::{Deserialize, Deserializer, Serializer};
use serde::de::{Error, Visitor};
use serde::{Deserializer, Serializer};

pub fn deserialize<'de, D: Deserializer<'de>>(deserializer: D) -> Result<u64, D::Error> {
deserializer.deserialize_any(SnowflakeVisitor)
Expand All @@ -281,39 +281,6 @@ pub(crate) mod snowflake {
fn visit_str<E: Error>(self, value: &str) -> Result<Self::Value, E> {
value.parse().map_err(Error::custom)
}

// This is called when serde_json's `arbitrary_precision` feature is enabled.
fn visit_map<A: MapAccess<'de>>(self, mut map: A) -> Result<Self::Value, A::Error> {
let id = map.next_value::<Snowflake>()?;
Ok(id.value)
}
}

struct Snowflake {
value: u64,
}

impl<'de> Deserialize<'de> for Snowflake {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
struct StrVisitor;

impl<'de> Visitor<'de> for StrVisitor {
type Value = Snowflake;

fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str("string containing a number")
}

fn visit_str<E: Error>(self, s: &str) -> Result<Snowflake, E> {
let value = s.parse().map_err(Error::custom)?;
Ok(Snowflake {
value,
})
}
}

deserializer.deserialize_str(StrVisitor)
}
}
}

Expand Down