From c1f3fe781f91914070815aa7085f659fe682c095 Mon Sep 17 00:00:00 2001 From: Raphael Taylor-Davies Date: Mon, 18 Sep 2023 15:20:20 +0100 Subject: [PATCH] fix: prost deprecations --- pbjson-build/src/generator/enumeration.rs | 6 ++---- pbjson-build/src/generator/message.rs | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/pbjson-build/src/generator/enumeration.rs b/pbjson-build/src/generator/enumeration.rs index 0eadc39..c833484 100644 --- a/pbjson-build/src/generator/enumeration.rs +++ b/pbjson-build/src/generator/enumeration.rs @@ -109,10 +109,9 @@ fn write_visitor( {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} }}) @@ -122,10 +121,9 @@ fn write_visitor( {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} }}) diff --git a/pbjson-build/src/generator/message.rs b/pbjson-build/src/generator/message.rs index 4834010..4203554 100644 --- a/pbjson-build/src/generator/message.rs +++ b/pbjson-build/src/generator/message.rs @@ -208,10 +208,10 @@ fn write_decode_variant( 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 )