Skip to content

Commit

Permalink
fix: prost deprecations (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
tustvold authored Sep 18, 2023
1 parent 255585b commit 9d19bfd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
6 changes: 2 additions & 4 deletions pbjson-build/src/generator/enumeration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,9 @@ fn write_visitor<W: Write>(
{indent} where
{indent} E: serde::de::Error,
{indent} {{
{indent} use std::convert::TryFrom;
{indent} i32::try_from(v)
{indent} .ok()
{indent} .and_then({rust_type}::from_i32)
{indent} .and_then(|x| x.try_into().ok())
{indent} .ok_or_else(|| {{
{indent} serde::de::Error::invalid_value(serde::de::Unexpected::Signed(v), &self)
{indent} }})
Expand All @@ -122,10 +121,9 @@ fn write_visitor<W: Write>(
{indent} where
{indent} E: serde::de::Error,
{indent} {{
{indent} use std::convert::TryFrom;
{indent} i32::try_from(v)
{indent} .ok()
{indent} .and_then({rust_type}::from_i32)
{indent} .and_then(|x| x.try_into().ok())
{indent} .ok_or_else(|| {{
{indent} serde::de::Error::invalid_value(serde::de::Unexpected::Unsigned(v), &self)
{indent} }})
Expand Down
4 changes: 2 additions & 2 deletions pbjson-build/src/generator/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,10 @@ fn write_decode_variant<W: Write>(
path: &TypePath,
writer: &mut W,
) -> Result<()> {
writeln!(writer, "{}::from_i32({})", resolver.rust_type(path), value)?;
writeln!(writer, "{}::try_from({})", resolver.rust_type(path), value)?;
write!(
writer,
"{}.ok_or_else(|| serde::ser::Error::custom(format!(\"Invalid variant {{}}\", {})))",
"{}.map_err(|_| serde::ser::Error::custom(format!(\"Invalid variant {{}}\", {})))",
Indent(indent),
value
)
Expand Down

0 comments on commit 9d19bfd

Please sign in to comment.