-
Notifications
You must be signed in to change notification settings - Fork 1
/
lib.rs
124 lines (109 loc) · 3.91 KB
/
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//! Derives for the `tatk` crate.
use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, DeriveInput};
/// An internal value used to calculate additional details on composite indicators.
#[proc_macro_derive(InternalValue)]
pub fn internal_value_derive(input: TokenStream) -> TokenStream {
// Parse the input tokens and the name of the struct.
let input: DeriveInput = parse_macro_input!(input as DeriveInput);
let struct_name = &input.ident;
// Generate the implementation of the InternalValue trait.
TokenStream::from(quote! {
impl InternalValue for #struct_name {
fn internal_value(&self) -> Num {
self.value
}
}
})
}
/// Enables the `period()` method. Period is the window of data to process.
#[proc_macro_derive(Period)]
pub fn period_derive(input: TokenStream) -> TokenStream {
// Parse the input tokens and the name of the struct.
let input: DeriveInput = parse_macro_input!(input as DeriveInput);
let struct_name = &input.ident;
// Generate the implementation of the Period trait.
TokenStream::from(quote! {
impl Period for #struct_name {
fn period(&self) -> usize {
self.period
}
}
})
}
/// Enables the `open()` method. Returns the opening value for the candle.
#[proc_macro_derive(Open)]
pub fn open_derive(input: TokenStream) -> TokenStream {
// Parse the input tokens and the name of the struct.
let input: DeriveInput = parse_macro_input!(input as DeriveInput);
let struct_name = &input.ident;
// Generate the implementation of the Open trait.
TokenStream::from(quote! {
impl Open for #struct_name {
fn open(&self) -> Num {
self.open
}
}
})
}
/// Enables the `close()` method. Returns the closing value for the candle.
#[proc_macro_derive(Close)]
pub fn close_derive(input: TokenStream) -> TokenStream {
// Parse the input tokens and the name of the struct.
let input: DeriveInput = parse_macro_input!(input as DeriveInput);
let struct_name = &input.ident;
// Generate the implementation of the Close trait.
TokenStream::from(quote! {
impl Close for #struct_name {
fn close(&self) -> Num {
self.close
}
}
})
}
/// Enables the `low()` method. Returns the lowest value for the candle.
#[proc_macro_derive(Low)]
pub fn low_derive(input: TokenStream) -> TokenStream {
// Parse the input tokens and the name of the struct.
let input: DeriveInput = parse_macro_input!(input as DeriveInput);
let struct_name = &input.ident;
// Generate the implementation of the Low trait.
TokenStream::from(quote! {
impl Low for #struct_name {
fn low(&self) -> Num {
self.low
}
}
})
}
/// Enables the `high()` method. Returns the highest value for the candle.
#[proc_macro_derive(High)]
pub fn high_derive(input: TokenStream) -> TokenStream {
// Parse the input tokens and the name of the struct.
let input: DeriveInput = parse_macro_input!(input as DeriveInput);
let struct_name = &input.ident;
// Generate the implementation of the High trait.
TokenStream::from(quote! {
impl High for #struct_name {
fn high(&self) -> Num {
self.high
}
}
})
}
/// Enables the `volume()` method. Returns the volume value for the candle.
#[proc_macro_derive(Volume)]
pub fn volume_derive(input: TokenStream) -> TokenStream {
// Parse the input tokens and the name of the struct.
let input: DeriveInput = parse_macro_input!(input as DeriveInput);
let struct_name = &input.ident;
// Generate the implementation of the Volume trait.
TokenStream::from(quote! {
impl Volume for #struct_name {
fn volume(&self) -> Num {
self.volume
}
}
})
}