rasn_derive/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/// Helper function print out the derive.
fn __print_stream(stream: proc_macro2::TokenStream) -> proc_macro::TokenStream {
    println!("{}", stream);
    stream.into()
}

/// An automatic derive of the `Decode` trait.
///
/// Will automatically generate a decode implementation using the your
/// container's definition. See [`AsnType`](`asn_type_derive`) for information
/// on available attributes.
#[proc_macro_derive(Decode, attributes(rasn))]
pub fn decode_derive(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
    rasn_derive_impl::decode_derive_inner(input.into())
        .unwrap_or_else(syn::Error::into_compile_error)
        .into()
}

/// An automatic derive of the `Encode` trait.
///
/// Will automatically generate a encode implementation using the your
/// container's definition. See [`AsnType`](`asn_type_derive`) for information
/// on available attributes.
#[proc_macro_derive(Encode, attributes(rasn))]
pub fn encode_derive(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
    rasn_derive_impl::encode_derive_inner(input.into())
        .unwrap_or_else(syn::Error::into_compile_error)
        .into()
}

/// An automatic derive of the `AsnType` trait.
///
/// This macro will automatically generate an implementation of `AsnType`,
/// and generate a *compile-time* check that all of your fields (if struct) or
/// variants (if a choice style enum) have distinct tags.
///
/// ##### Shared Attributes
/// These attributes are available on containers, variants, and fields.
/// - *`tag([class], number)`* — override the default tag with the one
///   specified with this attribute. E.g. `#[rasn(tag(context, 0))]`, you can also
///   wrapp `[class], number` in `explicit` to mark it as a explicit tag
///   (e.g.  `#[rasn(tag(explicit(0)))]`.)
///
/// ##### Container Attributes
/// - `crate_root` The path to the `rasn` library to use in the macro.
/// - `enumerated/choice` Use either `#[rasn(choice)]` or `#[rasn(enumerated)]`
/// - `delegate` Only available for newtype wrappers (e.g. `struct Delegate(T)`);
///   uses the inner `T` type for implementing the trait.
#[proc_macro_derive(AsnType, attributes(rasn))]
pub fn asn_type_derive(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
    rasn_derive_impl::asn_type_derive_inner(input.into())
        .unwrap_or_else(syn::Error::into_compile_error)
        .into()
}