Update ssz_derive for publishing to crates.io
This commit is contained in:
parent
027f0a539d
commit
54bda210e2
@ -4,6 +4,7 @@ version = "0.1.0"
|
|||||||
authors = ["Paul Hauner <paul@sigmaprime.io>"]
|
authors = ["Paul Hauner <paul@sigmaprime.io>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
description = "Procedural derive macros to accompany the eth2_ssz crate."
|
description = "Procedural derive macros to accompany the eth2_ssz crate."
|
||||||
|
license = "Apache-2.0"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "ssz_derive"
|
name = "ssz_derive"
|
||||||
@ -12,4 +13,3 @@ proc-macro = true
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
syn = "0.15"
|
syn = "0.15"
|
||||||
quote = "0.6"
|
quote = "0.6"
|
||||||
eth2_ssz = { path = "../ssz" }
|
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
#![recursion_limit = "128"]
|
#![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;
|
extern crate proc_macro;
|
||||||
|
|
||||||
@ -61,6 +64,10 @@ fn should_skip_serializing(field: &syn::Field) -> bool {
|
|||||||
/// Implements `ssz::Encode` for some `struct`.
|
/// Implements `ssz::Encode` for some `struct`.
|
||||||
///
|
///
|
||||||
/// Fields are encoded in the order they are defined.
|
/// 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))]
|
#[proc_macro_derive(Encode, attributes(ssz))]
|
||||||
pub fn ssz_encode_derive(input: TokenStream) -> TokenStream {
|
pub fn ssz_encode_derive(input: TokenStream) -> TokenStream {
|
||||||
let item = parse_macro_input!(input as DeriveInput);
|
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`.
|
/// Implements `ssz::Decode` for some `struct`.
|
||||||
///
|
///
|
||||||
/// Fields are decoded in the order they are defined.
|
/// 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)]
|
#[proc_macro_derive(Decode)]
|
||||||
pub fn ssz_decode_derive(input: TokenStream) -> TokenStream {
|
pub fn ssz_decode_derive(input: TokenStream) -> TokenStream {
|
||||||
let item = parse_macro_input!(input as DeriveInput);
|
let item = parse_macro_input!(input as DeriveInput);
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
use ssz::Encode;
|
|
||||||
use ssz_derive::Encode;
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Encode)]
|
|
||||||
pub struct Foo {
|
|
||||||
a: u16,
|
|
||||||
b: Vec<u8>,
|
|
||||||
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);
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user