Unverified Commit bdcbe67f authored by Bastian Köcher's avatar Bastian Köcher Committed by GitHub
Browse files

Port derive empty enum to master (#66)



* release parity-codec v3.2

* impl skip fields and variants (#58)

* impl skip variants

* impl skip on fields

* reorganize code

* in code rename

Co-Authored-By: thiolliere's avatarthiolliere <gui.thiolliere@gmail.com>

* in code rename

* code refactor

* refactor: variant filter

* new version of derive (#61)

* release codec-v3.3 that forward derive-v3.2 (#63)

* Implement derive for empty enums

* Bump version of parity-codec-derive to 3.3

* Fixes test
parent f264bbb1
......@@ -15,17 +15,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "parity-codec"
version = "3.1.0"
version = "3.3.0"
dependencies = [
"arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-codec-derive 3.1.0",
"parity-codec-derive 3.3.0",
"serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "parity-codec-derive"
version = "3.1.0"
version = "3.3.0"
dependencies = [
"proc-macro-crate 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)",
......
[package]
name = "parity-codec"
description = "Lightweight, efficient, binary serialization and deserialization codec"
version = "3.1.0"
version = "3.3.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "Apache-2.0"
repository = "https://github.com/paritytech/parity-codec"
......@@ -11,11 +11,11 @@ edition = "2018"
[dependencies]
arrayvec = { version = "0.4", default-features = false, features = ["array-sizes-33-128", "array-sizes-129-255"] }
serde = { version = "1.0", optional = true }
parity-codec-derive = { path = "derive", version = "3.1", default-features = false, optional = true }
parity-codec-derive = { path = "derive", version = "3.3", default-features = false, optional = true }
[dev-dependencies]
serde_derive = { version = "1.0" }
parity-codec-derive = { path = "derive", version = "3.1", default-features = false }
parity-codec-derive = { path = "derive", version = "3.3", default-features = false }
[features]
default = ["std"]
......
[package]
name = "parity-codec-derive"
description = "Serialization and deserialization derive macro for Parity Codec"
version = "3.1.0"
version = "3.3.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "Apache-2.0"
edition = "2018"
......
......@@ -208,6 +208,11 @@ fn impl_encode(data: &Data, type_name: &Ident) -> TokenStream {
).to_compile_error();
}
// If the enum has no variants, we don't need to encode anything.
if data_variants().count() == 0 {
return quote!();
}
let recurse = data_variants().enumerate().map(|(i, f)| {
let name = &f.ident;
let index = utils::index(f, i);
......
......@@ -454,3 +454,14 @@ fn recursive_variant_2_encode_works() {
let val: Recursive<u32, i32, u32> = Recursive::default();
val.encode();
}
#[test]
fn encode_decode_empty_enum() {
#[derive(Encode, Decode, PartialEq, Debug)]
enum EmptyEnumDerive {}
fn impls_encode_decode<T: Encode + Decode>() {}
impls_encode_decode::<EmptyEnumDerive>();
assert_eq!(EmptyEnumDerive::decode(&mut &[1, 2, 3][..]), Err("No such variant in enum EmptyEnumDerive".into()));
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment