File tree Expand file tree Collapse file tree 4 files changed +42
-2
lines changed
starlark_derive/src/module Expand file tree Collapse file tree 4 files changed +42
-2
lines changed Original file line number Diff line number Diff line change 17
17
18
18
mod basic;
19
19
mod default_value;
20
+ mod generic;
20
21
mod kwargs;
21
22
mod methods;
22
23
mod named_positional;
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2018 The Starlark in Rust Authors.
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * https://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ use starlark_derive:: starlark_module;
19
+
20
+ use crate as starlark;
21
+ use crate :: assert:: Assert ;
22
+ use crate :: environment:: GlobalsBuilder ;
23
+
24
+ #[ starlark_module]
25
+ fn generic_builder < T : Default , U > ( globals : & mut GlobalsBuilder )
26
+ where
27
+ U : std:: fmt:: Display + Default ,
28
+ {
29
+ const MY_STR : & str = & U :: default ( ) . to_string ( ) ;
30
+ }
31
+
32
+ #[ test]
33
+ fn test_generic_builder ( ) {
34
+ let mut a = Assert :: new ( ) ;
35
+ a. globals_add ( generic_builder :: < u8 , u8 > ) ;
36
+ a. eq ( "\" 0\" " , "MY_STR" ) ;
37
+ }
Original file line number Diff line number Diff line change @@ -743,7 +743,7 @@ fn test_label_assign() {
743
743
}
744
744
745
745
#[ starlark_module]
746
- fn module < ' v > ( builder : & mut GlobalsBuilder ) {
746
+ fn module ( builder : & mut GlobalsBuilder ) {
747
747
fn wrapper < ' v > ( heap : & ' v Heap ) -> anyhow:: Result < Value < ' v > > {
748
748
Ok ( heap. alloc_complex ( Wrapper ( RefCell :: new ( SmallMap :: new ( ) ) ) ) )
749
749
}
Original file line number Diff line number Diff line change @@ -68,11 +68,13 @@ fn render_impl(x: StarModule) -> syn::Result<syn::ItemFn> {
68
68
}
69
69
} ,
70
70
} ;
71
+ let turbo = input. sig . generics . split_for_impl ( ) . 1 ;
72
+ let turbo = turbo. as_turbofish ( ) ;
71
73
input. block = syn:: parse_quote! {
72
74
{
73
75
#inner_fn
74
76
static RES : starlark:: environment:: #statics = starlark:: environment:: #statics:: new( ) ;
75
- RES . populate( build, globals_builder) ;
77
+ RES . populate( build #turbo , globals_builder) ;
76
78
}
77
79
} ;
78
80
Ok ( input)
You can’t perform that action at this time.
0 commit comments