weblog_proc_macro/
lib.rs

1extern crate proc_macro2;
2
3mod weblog_impl;
4
5use proc_macro::TokenStream;
6use std::iter;
7use weblog_impl::{quote_console_func, ArgMode, ConsoleFunc};
8
9/// Call the browser's `console.assert()` function.
10/// [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Console/assert)
11#[proc_macro]
12pub fn console_assert(input: TokenStream) -> TokenStream {
13    quote_console_func(
14        ConsoleFunc::variadic("assert_with_condition_and_data", 1),
15        iter::once(ArgMode::PassThrough).chain(iter::repeat(ArgMode::IntoJsValue)),
16        input,
17    )
18}
19
20/// Call the browser's `console.clear()` function.
21/// [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Console/clear)
22#[proc_macro]
23pub fn console_clear(input: TokenStream) -> TokenStream {
24    quote_console_func(ConsoleFunc::fixed("clear", 0), iter::empty(), input)
25}
26
27/// Call the browser's `console.count()` function.
28/// [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Console/count)
29#[proc_macro]
30pub fn console_count(input: TokenStream) -> TokenStream {
31    let name = if input.is_empty() {
32        "count"
33    } else {
34        "count_with_label"
35    };
36
37    quote_console_func(
38        ConsoleFunc::fixed(name, 1),
39        iter::once(ArgMode::PassThrough),
40        input,
41    )
42}
43
44/// Call the browser's `console.countReset()` function.
45/// [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Console/countReset)
46#[proc_macro]
47pub fn console_count_reset(input: TokenStream) -> TokenStream {
48    let name = if input.is_empty() {
49        "count_reset"
50    } else {
51        "count_reset_with_label"
52    };
53
54    quote_console_func(
55        ConsoleFunc::fixed(name, 1),
56        iter::once(ArgMode::PassThrough),
57        input,
58    )
59}
60
61/// Call the browser's `console.debug()` function.
62/// [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Console/debug)
63#[proc_macro]
64pub fn console_debug(input: TokenStream) -> TokenStream {
65    quote_console_func(
66        ConsoleFunc::variadic("debug", 0),
67        iter::repeat(ArgMode::IntoJsValue),
68        input,
69    )
70}
71
72/// Call the browser's `console.dir()` function.
73/// [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Console/dir)
74#[proc_macro]
75pub fn console_dir(input: TokenStream) -> TokenStream {
76    quote_console_func(
77        ConsoleFunc::variadic("dir", 0),
78        iter::repeat(ArgMode::IntoJsValue),
79        input,
80    )
81}
82
83/// Call the browser's `console.dirxml()` function.
84/// [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Console/dirxml)
85#[proc_macro]
86pub fn console_dirxml(input: TokenStream) -> TokenStream {
87    quote_console_func(
88        ConsoleFunc::variadic("dirxml", 0),
89        iter::repeat(ArgMode::IntoJsValue),
90        input,
91    )
92}
93
94/// Call the browser's `console.error()` function.
95/// [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Console/error)
96#[proc_macro]
97pub fn console_error(input: TokenStream) -> TokenStream {
98    quote_console_func(
99        ConsoleFunc::variadic("error", 0),
100        iter::repeat(ArgMode::IntoJsValue),
101        input,
102    )
103}
104
105/// Call the browser's `console.exception()` function.
106/// [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Console/exception)
107#[proc_macro]
108pub fn console_exception(input: TokenStream) -> TokenStream {
109    quote_console_func(
110        ConsoleFunc::variadic("exception", 0),
111        iter::repeat(ArgMode::IntoJsValue),
112        input,
113    )
114}
115
116/// Call the browser's `console.info()` function.
117/// [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Console/info)
118#[proc_macro]
119pub fn console_info(input: TokenStream) -> TokenStream {
120    quote_console_func(
121        ConsoleFunc::variadic("info", 0),
122        iter::repeat(ArgMode::IntoJsValue),
123        input,
124    )
125}
126
127/// Call the browser's `console.log()` function.
128/// [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Console/log)
129#[proc_macro]
130pub fn console_log(input: TokenStream) -> TokenStream {
131    quote_console_func(
132        ConsoleFunc::variadic("log", 0),
133        iter::repeat(ArgMode::IntoJsValue),
134        input,
135    )
136}
137
138/// Call the browser's `console.table()` function.
139/// [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Console/table)
140#[proc_macro]
141pub fn console_table(input: TokenStream) -> TokenStream {
142    quote_console_func(
143        ConsoleFunc::variadic("table", 0),
144        iter::repeat(ArgMode::IntoJsValue),
145        input,
146    )
147}
148
149/// Call the browser's `console.time()` function.
150/// [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Console/time)
151#[proc_macro]
152pub fn console_time(input: TokenStream) -> TokenStream {
153    let name = if input.is_empty() {
154        "time"
155    } else {
156        "time_with_label"
157    };
158
159    quote_console_func(
160        ConsoleFunc::fixed(name, 1),
161        iter::once(ArgMode::PassThrough),
162        input,
163    )
164}
165
166/// Call the browser's `console.timeEnd()` function.
167/// [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Console/timeEnd)
168#[proc_macro]
169pub fn console_time_end(input: TokenStream) -> TokenStream {
170    let name = if input.is_empty() {
171        "time_end"
172    } else {
173        "time_end_with_label"
174    };
175
176    quote_console_func(
177        ConsoleFunc::fixed(name, 1),
178        iter::once(ArgMode::PassThrough),
179        input,
180    )
181}
182
183/// Call the browser's `console.timeLog()` function.
184/// [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Console/timeLog)
185#[proc_macro]
186pub fn console_time_log(input: TokenStream) -> TokenStream {
187    quote_console_func(
188        ConsoleFunc::variadic("time_log_with_label_and_data", 1),
189        iter::once(ArgMode::PassThrough).chain(iter::repeat(ArgMode::IntoJsValue)),
190        input,
191    )
192}
193
194/// Call the browser's `console.timeStamp()` function.
195/// [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Console/timeStamp)
196#[proc_macro]
197pub fn console_time_stamp(input: TokenStream) -> TokenStream {
198    let name = if input.is_empty() {
199        "time_stamp"
200    } else {
201        "time_stamp_with_data"
202    };
203
204    quote_console_func(
205        ConsoleFunc::fixed(name, 1),
206        iter::once(ArgMode::IntoJsValue),
207        input,
208    )
209}
210
211/// Call the browser's `console.trace()` function.
212/// [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Console/trace)
213#[proc_macro]
214pub fn console_trace(input: TokenStream) -> TokenStream {
215    quote_console_func(
216        ConsoleFunc::variadic("trace", 0),
217        iter::repeat(ArgMode::IntoJsValue),
218        input,
219    )
220}
221
222/// Call the browser's `console.warn()` function.
223/// [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Console/warn)
224#[proc_macro]
225pub fn console_warn(input: TokenStream) -> TokenStream {
226    quote_console_func(
227        ConsoleFunc::variadic("warn", 0),
228        iter::repeat(ArgMode::IntoJsValue),
229        input,
230    )
231}