Skip to content

Commit

Permalink
Fix ID type deserialization from signed integers (#1668)
Browse files Browse the repository at this point in the history
The TOML specification defines integers as 64-bit signed integers and the
deserializer calls `Visitor::visit_i64`.
  • Loading branch information
nickelc authored and arqunis committed Mar 15, 2022
1 parent b4d0765 commit ba84c77
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/model/id.rs
Expand Up @@ -251,6 +251,7 @@ id_u64! {
/// }
/// ```
pub(crate) mod snowflake {
use std::convert::TryFrom;
use std::fmt;

use serde::de::{Error, MapAccess, Visitor};
Expand All @@ -274,6 +275,11 @@ pub(crate) mod snowflake {
formatter.write_str("string or integer snowflake")
}

// Called by formats like TOML.
fn visit_i64<E: Error>(self, value: i64) -> Result<Self::Value, E> {
u64::try_from(value).map_err(Error::custom)
}

fn visit_u64<E: Error>(self, value: u64) -> Result<Self::Value, E> {
Ok(value)
}
Expand Down

0 comments on commit ba84c77

Please sign in to comment.