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

Implement empty enum derive (#65)

* Implement derive for empty enums

* Bump version of parity-codec-derive to 3.3

* Bump parity-codec as well
parent 0c4b6613
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "arrayvec"
version = "0.4.10"
......@@ -13,17 +15,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "parity-codec"
version = "3.3.0"
version = "3.4.0"
dependencies = [
"arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-codec-derive 3.2.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.2.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.3.0"
version = "3.4.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 }
serde = { version = "1.0", optional = true }
parity-codec-derive = { path = "derive", version = "3.2", 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.2", 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.2.0"
version = "3.3.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "Apache-2.0"
edition = "2018"
......
......@@ -115,6 +115,11 @@ pub fn quote(data: &Data, type_name: &Ident, self_: &TokenStream, dest: &TokenSt
).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);
......
......@@ -419,3 +419,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][..]), None);
}
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