Skip to content

Commit

Permalink
fix(worker): add missing utils.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
Gowee committed Nov 30, 2024
1 parent 016edd9 commit a80ce47
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions worker/src/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use serde::de::{self, Deserialize, Deserializer, Unexpected};

// src: https://github.com/serde-rs/serde/issues/1344#issuecomment-410309140
pub fn bool_from_int<'de, D>(deserializer: D) -> Result<bool, D::Error>
where
D: Deserializer<'de>,
{
match u8::deserialize(deserializer)? {
0 => Ok(false),
1 => Ok(true),
other => Err(de::Error::invalid_value(
Unexpected::Unsigned(other as u64),
&"zero or one",
)),
}
}

0 comments on commit a80ce47

Please sign in to comment.