@@ -10,7 +10,6 @@ extern crate proc_macro;
10
10
11
11
mod args;
12
12
13
- use std:: env;
14
13
use std:: fmt:: Write ;
15
14
use proc_macro2:: { Span , TokenStream } ;
16
15
use quote:: { quote, TokenStreamExt } ;
@@ -146,7 +145,6 @@ use self::args::{Class, ChildType};
146
145
#[ proc_macro_derive( Widget , attributes( core, widget, handler) ) ]
147
146
pub fn derive ( input : proc_macro:: TokenStream ) -> proc_macro:: TokenStream {
148
147
let mut ast = parse_macro_input ! ( input as DeriveInput ) ;
149
- let c = c ( ) ;
150
148
151
149
let args = match args:: read_attrs ( & mut ast) {
152
150
Ok ( w) => w,
@@ -159,7 +157,7 @@ pub fn derive(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
159
157
let class = args. widget . class ;
160
158
let count = args. children . len ( ) ;
161
159
162
- let layout_fns = match layout:: fns ( & c , & args. children , args. widget . layout ) {
160
+ let layout_fns = match layout:: fns ( & args. children , args. widget . layout ) {
163
161
Ok ( fns) => fns,
164
162
Err ( err) => return err. to_compile_error ( ) . into ( ) ,
165
163
} ;
@@ -176,58 +174,58 @@ pub fn derive(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
176
174
let get_mut_rules = make_match_rules ( & args. children , quote ! { mut } ) ;
177
175
178
176
let mut toks = quote ! {
179
- impl #impl_generics #c :: Core
177
+ impl #impl_generics kas :: Core
180
178
for #name #ty_generics #where_clause
181
179
{
182
180
fn number( & self ) -> u32 {
183
- use #c :: Core ;
181
+ use kas :: Core ;
184
182
self . #core. number( )
185
183
}
186
184
fn set_number( & mut self , number: u32 ) {
187
- use #c :: Core ;
185
+ use kas :: Core ;
188
186
self . #core. set_number( number) ;
189
187
}
190
188
191
- fn tkd( & self ) -> #c :: TkData {
192
- use #c :: Core ;
189
+ fn tkd( & self ) -> kas :: TkData {
190
+ use kas :: Core ;
193
191
self . #core. tkd( )
194
192
}
195
- fn set_tkd( & mut self , tkd: #c :: TkData ) {
196
- use #c :: Core ;
193
+ fn set_tkd( & mut self , tkd: kas :: TkData ) {
194
+ use kas :: Core ;
197
195
self . #core. set_tkd( tkd)
198
196
}
199
197
200
- fn rect( & self ) -> & #c :: Rect {
201
- use #c :: Core ;
198
+ fn rect( & self ) -> & kas :: Rect {
199
+ use kas :: Core ;
202
200
self . #core. rect( )
203
201
}
204
- fn rect_mut( & mut self ) -> & mut #c :: Rect {
205
- use #c :: Core ;
202
+ fn rect_mut( & mut self ) -> & mut kas :: Rect {
203
+ use kas :: Core ;
206
204
self . #core. rect_mut( )
207
205
}
208
206
}
209
207
210
- impl #impl_generics #c :: Layout
208
+ impl #impl_generics kas :: Layout
211
209
for #name #ty_generics #where_clause
212
210
{
213
211
#layout_fns
214
212
}
215
213
216
- impl #impl_generics #c :: Widget
214
+ impl #impl_generics kas :: Widget
217
215
for #name #ty_generics #where_clause
218
216
{
219
- fn class( & self ) -> #c :: Class { #class }
217
+ fn class( & self ) -> kas :: Class { #class }
220
218
221
219
fn len( & self ) -> usize {
222
220
#count
223
221
}
224
- fn get( & self , _index: usize ) -> Option <& #c :: Widget > {
222
+ fn get( & self , _index: usize ) -> Option <& kas :: Widget > {
225
223
match _index {
226
224
#get_rules
227
225
_ => None
228
226
}
229
227
}
230
- fn get_mut( & mut self , _index: usize ) -> Option <& mut #c :: Widget > {
228
+ fn get_mut( & mut self , _index: usize ) -> Option <& mut kas :: Widget > {
231
229
match _index {
232
230
#get_mut_rules
233
231
_ => None
@@ -276,15 +274,15 @@ pub fn derive(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
276
274
}
277
275
278
276
toks. append_all ( quote ! {
279
- impl #impl_generics #c :: event:: Handler
277
+ impl #impl_generics kas :: event:: Handler
280
278
for #name #ty_generics #where_clause
281
279
{
282
280
type Response = #response;
283
281
284
- fn handle_action( & mut self , _tk: & #c :: TkWidget , action: #c :: event:: Action ,
282
+ fn handle_action( & mut self , _tk: & kas :: TkWidget , action: kas :: event:: Action ,
285
283
num: u32 ) -> Self :: Response
286
284
{
287
- use #c :: { Core , event:: { Handler , err_unhandled, err_num} } ;
285
+ use kas :: { Core , event:: { Handler , err_unhandled, err_num} } ;
288
286
289
287
if num == self . number( ) {
290
288
// we may want to allow custom handlers on self here?
@@ -442,10 +440,8 @@ pub fn make_widget(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
442
440
// Used to make fresh identifiers for generic types
443
441
let mut name_buf = String :: with_capacity ( 32 ) ;
444
442
445
- let c = c ( ) ;
446
-
447
443
// fields of anonymous struct:
448
- let mut field_toks = quote ! { #[ core] core: #c :: CoreData , } ;
444
+ let mut field_toks = quote ! { #[ core] core: kas :: CoreData , } ;
449
445
// initialisers for these fields:
450
446
let mut field_val_toks = quote ! { core: Default :: default ( ) , } ;
451
447
// debug impl
@@ -463,10 +459,10 @@ pub fn make_widget(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
463
459
464
460
let widget_args = match args. class {
465
461
Class :: Container ( layout) => quote ! {
466
- class = #c :: Class :: Container , layout = #layout
462
+ class = kas :: Class :: Container , layout = #layout
467
463
} ,
468
464
Class :: Frame => quote ! {
469
- class = #c :: Class :: Frame
465
+ class = kas :: Class :: Frame
470
466
} ,
471
467
} ;
472
468
@@ -492,32 +488,32 @@ pub fn make_widget(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
492
488
gen_tys. push ( ty. clone ( ) ) ;
493
489
if let Some ( ref wattr) = attr {
494
490
if let Some ( tyr) = gen_response {
495
- handler_clauses. push ( quote ! { #ty: #c :: event:: Handler <Response = #tyr> } ) ;
491
+ handler_clauses. push ( quote ! { #ty: kas :: event:: Handler <Response = #tyr> } ) ;
496
492
} else {
497
493
// No typing. If a handler is specified, then the child must implement
498
494
// Handler<Response = X> where the handler takes type X; otherwise
499
495
// we use `msg.into()` and this conversion must be supported.
500
496
if let Some ( ref handler) = wattr. args . handler {
501
497
if let Some ( ty_bound) = find_handler_ty ( handler, & args. impls ) {
502
- handler_clauses. push ( quote ! { #ty: #c :: event:: Handler <Response = #ty_bound> } ) ;
498
+ handler_clauses. push ( quote ! { #ty: kas :: event:: Handler <Response = #ty_bound> } ) ;
503
499
} else {
504
500
return quote ! { } . into ( ) ; // exit after emitting error
505
501
}
506
502
} else {
507
503
name_buf. push_str ( "R" ) ;
508
504
let tyr = Ident :: new ( & name_buf, Span :: call_site ( ) ) ;
509
505
handler_extra. push ( tyr. clone ( ) ) ;
510
- handler_clauses. push ( quote ! { #ty: #c :: event:: Handler <Response = #tyr> } ) ;
511
- handler_clauses. push ( quote ! { #tyr: From <#c :: event:: NoResponse > } ) ;
506
+ handler_clauses. push ( quote ! { #ty: kas :: event:: Handler <Response = #tyr> } ) ;
507
+ handler_clauses. push ( quote ! { #tyr: From <kas :: event:: NoResponse > } ) ;
512
508
handler_clauses. push ( quote ! { #response: From <#tyr> } ) ;
513
509
}
514
510
}
515
511
516
512
if let Some ( mut bound) = gen_bound {
517
- bound. bounds . push ( parse_quote ! { #c :: Widget } ) ;
513
+ bound. bounds . push ( parse_quote ! { kas :: Widget } ) ;
518
514
gen_ptrs. push ( quote ! { #ty: #bound } ) ;
519
515
} else {
520
- gen_ptrs. push ( quote ! { #ty: #c :: Widget } ) ;
516
+ gen_ptrs. push ( quote ! { #ty: kas :: Widget } ) ;
521
517
}
522
518
} else {
523
519
gen_ptrs. push ( quote ! { #ty } ) ;
@@ -563,7 +559,7 @@ pub fn make_widget(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
563
559
let toks = ( quote ! { {
564
560
#[ widget( #widget_args) ]
565
561
#[ handler( response = #response, generics = < #handler_extra > #handler_where) ]
566
- #[ derive( Clone , Debug , #c :: macros:: Widget ) ]
562
+ #[ derive( Clone , Debug , kas :: macros:: Widget ) ]
567
563
struct AnonWidget <#gen_ptrs> {
568
564
#field_toks
569
565
}
@@ -585,28 +581,17 @@ pub fn make_widget(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
585
581
#[ proc_macro_derive( NoResponse ) ]
586
582
pub fn derive_no_response ( input : proc_macro:: TokenStream ) -> proc_macro:: TokenStream {
587
583
let ast = parse_macro_input ! ( input as DeriveInput ) ;
588
- let c = c ( ) ;
589
584
let ( impl_generics, ty_generics, where_clause) = ast. generics . split_for_impl ( ) ;
590
585
let name = & ast. ident ;
591
586
592
587
let toks = quote ! {
593
- impl #impl_generics From <#c :: event:: NoResponse >
588
+ impl #impl_generics From <kas :: event:: NoResponse >
594
589
for #name #ty_generics #where_clause
595
590
{
596
- fn from( _: #c :: event:: NoResponse ) -> Self {
591
+ fn from( _: kas :: event:: NoResponse ) -> Self {
597
592
#name:: None
598
593
}
599
594
}
600
595
} ;
601
596
toks. into ( )
602
597
}
603
-
604
- // Our stand-in for $crate. Imperfect, but works (excepting other crates in
605
- // the same package, i.e. doc-tests, examples, integration tests, benches).
606
- fn c ( ) -> TokenStream {
607
- if env:: var ( "CARGO_PKG_NAME" ) == Ok ( "kas" . to_string ( ) ) {
608
- parse_quote ! ( crate )
609
- } else {
610
- parse_quote ! ( kas )
611
- }
612
- }
0 commit comments