multihash_derive_impl/
lib.rs

1//! This is an internal crate that implements the actual `MultihashDigest` derive.
2//!
3//! The `multihash-derive` crate acts as a facade and defines additional symbols that our derive depends on.
4//! For example, the actual trait that we are deriving `MultihashDigest`, as well as the `Hasher` trait and
5//! the `UnsupportedCode` error type.
6
7extern crate proc_macro;
8
9mod multihash;
10mod utils;
11
12use proc_macro::TokenStream;
13use synstructure::macros::{parse, DeriveInput};
14use synstructure::{MacroResult, Structure};
15
16#[proc_macro_derive(Multihash, attributes(mh))]
17#[allow(non_snake_case)]
18#[deprecated(since = "0.8.1", note = "Use `MultihashDigest` derive instead.")]
19pub fn Multihash(i: TokenStream) -> TokenStream {
20    match parse::<DeriveInput>(i) {
21        Ok(p) => match Structure::try_new(&p) {
22            Ok(s) => multihash::multihash(s).into_stream(),
23            Err(e) => e.to_compile_error().into(),
24        },
25        Err(e) => e.to_compile_error().into(),
26    }
27}
28
29/// Custom derive for the `MultihashDigest` trait.
30#[proc_macro_derive(MultihashDigest, attributes(mh))]
31#[allow(non_snake_case)]
32pub fn MultihashDigest(i: TokenStream) -> TokenStream {
33    #[allow(deprecated)]
34    Multihash(i)
35}