From 54bda210e209c55b692d0d4256990e6ca8525e4f Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Thu, 4 Jul 2019 13:22:33 +1000 Subject: [PATCH] Update ssz_derive for publishing to crates.io --- eth2/utils/ssz_derive/Cargo.toml | 2 +- eth2/utils/ssz_derive/src/lib.rs | 13 +++++++++++++ eth2/utils/ssz_derive/tests/tests.rs | 22 ---------------------- 3 files changed, 14 insertions(+), 23 deletions(-) delete mode 100644 eth2/utils/ssz_derive/tests/tests.rs diff --git a/eth2/utils/ssz_derive/Cargo.toml b/eth2/utils/ssz_derive/Cargo.toml index 0b76f6153..db25e16be 100644 --- a/eth2/utils/ssz_derive/Cargo.toml +++ b/eth2/utils/ssz_derive/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" authors = ["Paul Hauner "] edition = "2018" description = "Procedural derive macros to accompany the eth2_ssz crate." +license = "Apache-2.0" [lib] name = "ssz_derive" @@ -12,4 +13,3 @@ proc-macro = true [dependencies] syn = "0.15" quote = "0.6" -eth2_ssz = { path = "../ssz" } diff --git a/eth2/utils/ssz_derive/src/lib.rs b/eth2/utils/ssz_derive/src/lib.rs index ef6e2440f..47d96859e 100644 --- a/eth2/utils/ssz_derive/src/lib.rs +++ b/eth2/utils/ssz_derive/src/lib.rs @@ -1,4 +1,7 @@ #![recursion_limit = "128"] +//! Provides procedural derive macros for the `Encode` and `Decode` traits of the `eth2_ssz` crate. +//! +//! Supports field attributes, see each derive macro for more information. extern crate proc_macro; @@ -61,6 +64,10 @@ fn should_skip_serializing(field: &syn::Field) -> bool { /// Implements `ssz::Encode` for some `struct`. /// /// Fields are encoded in the order they are defined. +/// +/// ## Field attributes +/// +/// - `#[ssz(skip_serializing)]`: the field will not be serialized. #[proc_macro_derive(Encode, attributes(ssz))] pub fn ssz_encode_derive(input: TokenStream) -> TokenStream { let item = parse_macro_input!(input as DeriveInput); @@ -132,6 +139,12 @@ fn should_skip_deserializing(field: &syn::Field) -> bool { /// Implements `ssz::Decode` for some `struct`. /// /// Fields are decoded in the order they are defined. +/// +/// ## Field attributes +/// +/// - `#[ssz(skip_deserializing)]`: during de-serialization the field will be instantiated from a +/// `Default` implementation. The decoder will assume that the field was not serialized at all +/// (e.g., if it has been serialized, an error will be raised instead of `Default` overriding it). #[proc_macro_derive(Decode)] pub fn ssz_decode_derive(input: TokenStream) -> TokenStream { let item = parse_macro_input!(input as DeriveInput); diff --git a/eth2/utils/ssz_derive/tests/tests.rs b/eth2/utils/ssz_derive/tests/tests.rs deleted file mode 100644 index d58db3b62..000000000 --- a/eth2/utils/ssz_derive/tests/tests.rs +++ /dev/null @@ -1,22 +0,0 @@ -use ssz::Encode; -use ssz_derive::Encode; - -#[derive(Debug, PartialEq, Encode)] -pub struct Foo { - a: u16, - b: Vec, - c: u16, -} - -#[test] -fn encode() { - let foo = Foo { - a: 42, - b: vec![0, 1, 2, 3], - c: 11, - }; - - let bytes = vec![42, 0, 8, 0, 0, 0, 11, 0, 0, 1, 2, 3]; - - assert_eq!(foo.as_ssz_bytes(), bytes); -}