Skip to content

Commit

Permalink
Remove serde impls for Fixed/Signed types (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
goffrie authored Feb 13, 2024
1 parent cb60567 commit 4b8b535
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 21 deletions.
19 changes: 8 additions & 11 deletions pb-jelly-gen/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ impl<'a, 'ctx> CodeWriter<'a, 'ctx> {
let ctx = self;
ctx.write_comments(ctx.source_code_info_by_scl.get(scl).copied());
if ctx.derive_serde {
ctx.write("#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash, Deserialize, Serialize)]");
ctx.write("#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash, ::serde_derive::Deserialize, ::serde_derive::Serialize)]");
} else {
ctx.write("#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]");
}
Expand Down Expand Up @@ -1043,7 +1043,7 @@ impl<'a, 'ctx> CodeWriter<'a, 'ctx> {
// Generate an open enum
ctx.write_comments(ctx.source_code_info_by_scl.get(scl).copied());
if ctx.derive_serde {
ctx.write("#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize)]");
ctx.write("#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, ::serde_derive::Deserialize, ::serde_derive::Serialize)]");
} else {
ctx.write("#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]");
}
Expand Down Expand Up @@ -1218,7 +1218,7 @@ impl<'a, 'ctx> CodeWriter<'a, 'ctx> {

let mut derives = vec!["Clone", "Debug", "PartialEq"];
if ctx.derive_serde {
derives.extend(["Deserialize", "Serialize"]);
derives.extend(["::serde_derive::Deserialize", "::serde_derive::Serialize"]);
}

let impls = &ctx.ctx.impls_by_msg[&ProtoType::new(
Expand Down Expand Up @@ -2552,16 +2552,12 @@ impl<'a> Context<'a> {

all_deps.remove("std");

let mut features: IndexMap<&str, &str> = [
("serde", r#"features=["serde_derive"]"#),
("compact_str", r#"features=["bytes"]"#),
]
.iter()
.copied()
.collect();
let mut features: IndexMap<&str, &str> =
[("compact_str", r#"features=["bytes"]"#)].iter().copied().collect();

if derive_serde {
all_deps.insert("serde");
all_deps.insert("serde_derive");
features.insert("compact_str", r#"features=["bytes", "serde"]"#);
}

Expand Down Expand Up @@ -2596,18 +2592,19 @@ impl<'a> Context<'a> {
all_deps.remove("std");

let mut features: BTreeMap<&str, String> = BTreeMap::new();
features.insert("serde", "features=[\"serde_derive\"]".to_string());
features.insert("compact_str", "features=[\"bytes\"]".to_string());

if derive_serde {
all_deps.insert("serde");
all_deps.insert("serde_derive");
features.insert("compact_str", "features=[\"bytes\", \"serde\"]".to_string());
}

let mut versions: IndexMap<&str, String> = IndexMap::new();
versions.insert("lazy_static", "version = \"1.4.0\"".to_string());
versions.insert("pb-jelly", "version = \"0.0.16\"".to_string());
versions.insert("serde", "version = \"1.0\"".to_string());
versions.insert("serde_derive", "version = \"1.0\"".to_string());
versions.insert("bytes", "version = \"1.0\"".to_string());
versions.insert("compact_str", "version = \"0.5\"".to_string());

Expand Down
1 change: 0 additions & 1 deletion pb-jelly/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ categories = ["encoding", "parsing", "web-programming"]
byteorder = "1.4"
bytes = "1.0"
compact_str = { version = "0.5", features = ["bytes"] }
serde = { version = "1.0", features = ["derive"] }
12 changes: 6 additions & 6 deletions pb-jelly/src/base_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ impl Message for i64 {

impl Reflection for i64 {}

#[derive(Clone, Copy, Default, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Deserialize, Serialize)]
#[derive(Clone, Copy, Default, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct Signed64(pub i64);

impl Signed64 {
Expand Down Expand Up @@ -259,7 +259,7 @@ impl DerefMut for Signed64 {
}
}

#[derive(Clone, Copy, Default, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Deserialize, Serialize)]
#[derive(Clone, Copy, Default, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct Signed32(pub i32);

impl Signed32 {
Expand Down Expand Up @@ -306,7 +306,7 @@ impl DerefMut for Signed32 {
}
}

#[derive(Clone, Copy, Default, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Deserialize, Serialize)]
#[derive(Clone, Copy, Default, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct Fixed64(pub u64);

impl Message for Fixed64 {
Expand Down Expand Up @@ -342,7 +342,7 @@ impl DerefMut for Fixed64 {
}
}

#[derive(Clone, Copy, Default, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Deserialize, Serialize)]
#[derive(Clone, Copy, Default, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct Fixed32(pub u32);

impl Message for Fixed32 {
Expand Down Expand Up @@ -378,7 +378,7 @@ impl DerefMut for Fixed32 {
}
}

#[derive(Clone, Copy, Default, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Deserialize, Serialize)]
#[derive(Clone, Copy, Default, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct Sfixed64(pub i64);

impl Message for Sfixed64 {
Expand Down Expand Up @@ -414,7 +414,7 @@ impl DerefMut for Sfixed64 {
}
}

#[derive(Clone, Copy, Default, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Deserialize, Serialize)]
#[derive(Clone, Copy, Default, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct Sfixed32(pub i32);

impl Message for Sfixed32 {
Expand Down
3 changes: 0 additions & 3 deletions pb-jelly/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
#![allow(clippy::cast_possible_truncation)]
#![allow(clippy::cast_possible_wrap)]

#[macro_use]
extern crate serde;

use std::any::Any;
use std::collections::BTreeMap;
use std::default::Default;
Expand Down

0 comments on commit 4b8b535

Please sign in to comment.