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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! # twilight-interactions-derive
//!
//! This crate provide derive macros for the `twilight-interactions` crate.
//!
//! Please refer to the `twilight-interactions` documentation for further information.

mod command;
mod option;
mod parse;

use proc_macro::TokenStream;
use syn::{parse_macro_input, DeriveInput};

/// Derive macro for the the `CommandModel` trait.
///
/// See the documentation of the trait for more information about usage of this macro.
#[proc_macro_derive(CommandModel, attributes(command))]
pub fn command_model(input: TokenStream) -> TokenStream {
    let input = parse_macro_input!(input as DeriveInput);
    let ident = input.ident.clone();

    match command::impl_command_model(input) {
        Ok(output) => output.into(),
        Err(error) => command::dummy_command_model(ident, error).into(),
    }
}

/// Derive macro for the the `CreateCommand` trait.
///
/// See the documentation of the trait for more information about usage of this macro.
#[proc_macro_derive(CreateCommand, attributes(command))]
pub fn create_command(input: TokenStream) -> TokenStream {
    let input = parse_macro_input!(input as DeriveInput);
    let ident = input.ident.clone();

    match command::impl_create_command(input) {
        Ok(output) => output.into(),
        Err(error) => command::dummy_create_command(ident, error).into(),
    }
}

/// Derive macro for the the `CommandOption` trait.
///
/// See the documentation of the trait for more information about usage of this macro.
#[proc_macro_derive(CommandOption, attributes(option))]
pub fn command_option(input: TokenStream) -> TokenStream {
    let input = parse_macro_input!(input as DeriveInput);
    let ident = input.ident.clone();

    match option::impl_command_option(input) {
        Ok(output) => output.into(),
        Err(error) => option::dummy_command_option(ident, error).into(),
    }
}

/// Derive macro for the the `CreateOption` trait.
///
/// See the documentation of the trait for more information about usage of this macro.
#[proc_macro_derive(CreateOption, attributes(option))]
pub fn create_option(input: TokenStream) -> TokenStream {
    let input = parse_macro_input!(input as DeriveInput);
    let ident = input.ident.clone();

    match option::impl_create_option(input) {
        Ok(output) => output.into(),
        Err(error) => option::dummy_create_option(ident, error).into(),
    }
}