Skip to content

Commit

Permalink
Updated rust edition to 2021.
Browse files Browse the repository at this point in the history
  • Loading branch information
fdeantoni committed Jan 8, 2023
1 parent f1d7a49 commit 08134fe
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ repository = "https://github.com/fdeantoni/prost-wkt"
description = "Helper crate for prost to allow JSON serialization and deserialization of Well Known Types."
readme = "README.md"
documentation = "https://docs.rs/prost-wkt-derive"
edition = "2018"
edition = "2021"

[workspace]
members = [ "wkt-build", "wkt-types", "example" ]
Expand Down
2 changes: 1 addition & 1 deletion example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "prost-wkt-example"
version = "0.3.4"
authors = ["fdeantoni <fdeantoni@gmail.com>"]
edition = "2018"
edition = "2021"

[dependencies]
prost = "0.11.5"
Expand Down
4 changes: 2 additions & 2 deletions example/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn main() -> Result<(), AnyError> {

let json = serde_json::to_string_pretty(&request).expect("Failed to serialize request");

println!("JSON:\n{}", json);
println!("JSON:\n{json}");

let back: Request = serde_json::from_str(&json).expect("Failed to deserialize request");

Expand All @@ -31,7 +31,7 @@ fn main() -> Result<(), AnyError> {
let unpacked_foo: &Foo = unpacked
.downcast_ref::<Foo>()
.expect("Failed to downcast message");
println!("Unpacked: {:?}", unpacked_foo);
println!("Unpacked: {unpacked_foo:?}");
}
Ok(())
}
3 changes: 1 addition & 2 deletions wkt-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ repository = "https://github.com/fdeantoni/prost-wkt"
description = "Helper crate for prost to allow JSON serialization and deserialization of Well Known Types."
readme = "../README.md"
documentation = "https://docs.rs/prost-wkt-build"
edition = "2018"
edition = "2021"

[dependencies]
prost = "0.11.5"
prost-types = "0.11.5"
prost-build = "0.11.5"
quote = "1.0"
heck = "0.4"

2 changes: 1 addition & 1 deletion wkt-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub fn add_serde(out: PathBuf, descriptor: FileDescriptorSet) {
None => continue,
};

let type_url = format!("type.googleapis.com/{}.{}", package_name, message_name);
let type_url = format!("type.googleapis.com/{package_name}.{message_name}");

gen_trait_impl(&mut rust_file, package_name, message_name, &type_url);
}
Expand Down
2 changes: 1 addition & 1 deletion wkt-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ readme = "../README.md"
documentation = "https://docs.rs/prost-wkt"
keywords = ["protobuf", "serde", "json"]
categories = ["encoding"]
edition = "2018"
edition = "2021"

[lib]
doctest = false
Expand Down
2 changes: 1 addition & 1 deletion wkt-types/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn main() {
fn build(dir: &Path, proto: &str) {
let out = dir.join(proto);
create_dir_all(&out).unwrap();
let source = format!("proto/{}.proto", proto);
let source = format!("proto/{proto}.proto");
let descriptor_file = out.join("descriptors.bin");
let mut prost_build = prost_build::Config::new();
prost_build
Expand Down
14 changes: 7 additions & 7 deletions wkt-types/src/pbany.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ impl std::fmt::Display for AnyError {

impl From<prost::DecodeError> for AnyError {
fn from(error: DecodeError) -> Self {
AnyError::new(format!("Error decoding message: {:?}", error))
AnyError::new(format!("Error decoding message: {error:?}"))
}
}

impl From<prost::EncodeError> for AnyError {
fn from(error: prost::EncodeError) -> Self {
AnyError::new(format!("Error encoding message: {:?}", error))
AnyError::new(format!("Error encoding message: {error:?}"))
}
}

Expand Down Expand Up @@ -153,7 +153,7 @@ impl<'de> Deserialize<'de> for Any {
serde::de::Deserialize::deserialize(deserializer)?;
let type_url = erased.type_url().to_string();
let value = erased.try_encoded().map_err(|err| {
serde::de::Error::custom(format!("Failed to encode message: {:?}", err))
serde::de::Error::custom(format!("Failed to encode message: {err:?}"))
})?;
Ok(Any { type_url, value })
}
Expand Down Expand Up @@ -215,9 +215,9 @@ mod tests {
string: "Hello World!".to_string(),
};
let any = Any::try_pack(msg.clone()).unwrap();
println!("{:?}", any);
println!("{any:?}");
let unpacked = any.unpack_as(Foo::default()).unwrap();
println!("{:?}", unpacked);
println!("{unpacked:?}");
assert_eq!(unpacked, msg)
}

Expand All @@ -227,7 +227,7 @@ mod tests {
string: "Hello World!".to_string(),
};
let any = Any::try_pack(msg.clone()).unwrap();
println!("{:?}", any);
println!("{any:?}");
let unpacked: &dyn MessageSerde = &any.unpack_as(Foo::default()).unwrap();
let downcast = unpacked.downcast_ref::<Foo>().unwrap();
assert_eq!(downcast, &msg);
Expand All @@ -242,7 +242,7 @@ mod tests {
});
let erased: Box<dyn MessageSerde> = serde_json::from_value(data).unwrap();
let foo: &Foo = erased.downcast_ref::<Foo>().unwrap();
println!("Deserialize default: {:?}", foo);
println!("Deserialize default: {foo:?}");
assert_eq!(foo, &Foo::default())
}
}
12 changes: 6 additions & 6 deletions wkt-types/src/pbstruct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,21 +315,21 @@ mod tests {
#[test]
fn conversion_test() {
let number: Value = Value::from(10.0);
println!("Number: {:?}", number);
println!("Number: {number:?}");
let null: Value = Value::null();
println!("Null: {:?}", null);
println!("Null: {null:?}");
let string: Value = Value::from(String::from("Hello"));
println!("String: {:?}", string);
println!("String: {string:?}");
let list = vec![Value::null(), Value::from(100.0)];
let pb_list: Value = Value::from(list);
println!("List: {:?}", pb_list);
println!("List: {pb_list:?}");
let mut map: HashMap<String, Value> = HashMap::new();
map.insert(String::from("number"), number);
map.insert(String::from("null"), null);
map.insert(String::from("string"), string);
map.insert(String::from("list"), pb_list);
let pb_struct: Value = Value::from(map);
println!("Struct: {:?}", pb_struct);
println!("Struct: {pb_struct:?}");
}

#[test]
Expand All @@ -352,7 +352,7 @@ mod tests {
}"#;
let sj: serde_json::Value = serde_json::from_str(data).unwrap();
let pj: Value = serde_json::from_value(sj.clone()).unwrap();
println!("prost_wkt_types Value: {:?}", pj);
println!("prost_wkt_types Value: {pj:?}");
let string: String = serde_json::to_string(&pj).unwrap();
let back: serde_json::Value = serde_json::from_str(&string).unwrap();
assert_eq!(sj, back);
Expand Down
7 changes: 3 additions & 4 deletions wkt-types/src/pbtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl Serialize for Timestamp {
};
ts.normalize();
let dt: DateTime<Utc> = ts.try_into().map_err(serde::ser::Error::custom)?;
serializer.serialize_str(format!("{:?}", dt).as_str())
serializer.serialize_str(format!("{dt:?}").as_str())
}
}

Expand All @@ -81,8 +81,7 @@ impl<'de> Deserialize<'de> for Timestamp {
{
let utc: DateTime<Utc> = chrono::DateTime::from_str(value).map_err(|err| {
serde::de::Error::custom(format!(
"Failed to parse {} as datetime: {:?}",
value, err
"Failed to parse {value} as datetime: {err:?}"
))
})?;
let ts = Timestamp::from(utc);
Expand All @@ -107,6 +106,6 @@ mod tests {
};
let datetime_utc: DateTime<Utc> = ts.into();

println!("{:?}", datetime_utc);
println!("{datetime_utc:?}");
}
}
8 changes: 4 additions & 4 deletions wkt-types/tests/pbany_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ fn test_any_serialization() {
);
let erased = &msg as &dyn MessageSerde;
let json = serde_json::to_string(erased).unwrap();
println!("Erased json: {}", json);
println!("Erased json: {json}");
}

#[test]
Expand All @@ -132,7 +132,7 @@ fn test_any_deserialize_string() {
"list": []
}"#;
let msg: Foo = serde_json::from_str(data).unwrap();
println!("Deserialized from string: {:?}", msg);
println!("Deserialized from string: {msg:?}");
}

#[test]
Expand All @@ -159,7 +159,7 @@ fn test_any_serialize_deserialize() {
};

let json = serde_json::to_string(&original).unwrap();
println!("Serialized Foo: {}", json);
println!("Serialized Foo: {json}");
let back: Foo = serde_json::from_str(&json).unwrap();
println!("Deserialized Foo: {:?}", &back);
assert_eq!(back, original)
Expand All @@ -179,6 +179,6 @@ fn test_any_unpack() {
let any = prost_wkt_types::Any::try_pack(payload).unwrap();
let unpacked = any.try_unpack().unwrap();
let foo = unpacked.downcast_ref::<Foo>().unwrap();
println!("Unpacked: {:?}", foo);
println!("Unpacked: {foo:?}");
assert_eq!(foo.string, "hello payload");
}

0 comments on commit 08134fe

Please sign in to comment.