Skip to content

Commit fefe8e7

Browse files
David Tolnayfacebook-github-bot
David Tolnay
authored andcommitted
Factor out annotated type generics to separate template
Summary: The new `{{> lib/type_generics}}` template generates the `<T>` in Vec<T> and BTreeSet<T>, and the `<T, U>` in BTreeMap<T, U>, and in custom types specified through `rust.Type`. Beyond deduplicating the existing 2 uses (field types `{{field:type_rust}}`, service method argument types `{{type:rust}}`), I need to use this same logic a third time for typedef types `{{typedef:rust_type}}` in {D68909054}. Reviewed By: emersonford Differential Revision: D68927538 fbshipit-source-id: 9ceee895f092de98d97bf3222749cb86f1b3f618
1 parent d08827b commit fefe8e7

File tree

3 files changed

+49
-30
lines changed

3 files changed

+49
-30
lines changed

third-party/thrift/src/thrift/compiler/generate/templates/rust/lib/annfieldtype.mustache

+3-16
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,12 @@
2727
}}{{/type:struct}}{{!
2828
}}{{#type:enum}}{{enum:package}}::{{enum:rust_name}}{{/type:enum}}{{!
2929
}}{{#type:list?}}
30-
}}::std::vec::Vec<{{#type:list_elem_type}}{{> lib/type}}{{/type:list_elem_type}}>{{!
30+
}}::std::vec::Vec{{> lib/type_generics}}{{!
3131
}}{{/type:list?}}{{!
3232
}}{{#type:set?}}{{!
33-
}}::{{field:type_rust}}{{!
34-
}}<{{!
35-
}}{{#type:set_elem_type}}{{!
36-
}}{{#type:floating_point?}}::fbthrift::export::OrderedFloat<{{> lib/type}}>{{/type:floating_point?}}{{!
37-
}}{{^type:floating_point?}}{{> lib/type}}{{/type:floating_point?}}{{!
38-
}}{{/type:set_elem_type}}{{!
39-
}}>{{!
33+
}}::{{field:type_rust}}{{> lib/type_generics}}{{!
4034
}}{{/type:set?}}{{!
4135
}}{{#type:map?}}{{!
42-
}}::{{field:type_rust}}{{!
43-
}}<{{!
44-
}}{{#type:key_type}}{{!
45-
}}{{#type:floating_point?}}::fbthrift::export::OrderedFloat<{{> lib/type}}>{{/type:floating_point?}}{{!
46-
}}{{^type:floating_point?}}{{> lib/type}}{{/type:floating_point?}}{{!
47-
}}{{/type:key_type}}, {{!
48-
}}{{#type:value_type}}{{> lib/type}}{{/type:value_type}}{{!
49-
}}>{{!
36+
}}::{{field:type_rust}}{{> lib/type_generics}}{{!
5037
}}{{/type:map?}}{{!
5138
}}

third-party/thrift/src/thrift/compiler/generate/templates/rust/lib/rawtype.mustache

+3-14
Original file line numberDiff line numberDiff line change
@@ -48,27 +48,16 @@
4848
}}{{enum:package}}::{{enum:rust_name}}{{!
4949
}}{{/type:enum}}{{!
5050
}}{{#type:list?}}{{!
51-
}}::std::vec::Vec<{{#type:list_elem_type}}{{> lib/type}}{{/type:list_elem_type}}>{{!
51+
}}::std::vec::Vec{{> lib/type_generics}}{{!
5252
}}{{/type:list?}}{{!
5353
}}{{#type:set?}}{{!
5454
}}{{#type:rust}}::{{type:rust}}{{/type:rust}}{{!
5555
}}{{^type:rust}}::std::collections::BTreeSet{{/type:rust}}{{!
56-
}}<{{!
57-
}}{{#type:set_elem_type}}{{!
58-
}}{{#type:floating_point?}}::fbthrift::export::OrderedFloat<{{> lib/type}}>{{/type:floating_point?}}{{!
59-
}}{{^type:floating_point?}}{{> lib/type}}{{/type:floating_point?}}{{!
60-
}}{{/type:set_elem_type}}{{!
61-
}}>{{!
56+
}}{{> lib/type_generics}}{{!
6257
}}{{/type:set?}}{{!
6358
}}{{#type:map?}}{{!
6459
}}{{#type:rust}}::{{type:rust}}{{/type:rust}}{{!
6560
}}{{^type:rust}}::std::collections::BTreeMap{{/type:rust}}{{!
66-
}}<{{!
67-
}}{{#type:key_type}}{{!
68-
}}{{#type:floating_point?}}::fbthrift::export::OrderedFloat<{{> lib/type}}>{{/type:floating_point?}}{{!
69-
}}{{^type:floating_point?}}{{> lib/type}}{{/type:floating_point?}}{{!
70-
}}{{/type:key_type}}, {{!
71-
}}{{#type:value_type}}{{> lib/type}}{{/type:value_type}}{{!
72-
}}>{{!
61+
}}{{> lib/type_generics}}{{!
7362
}}{{/type:map?}}{{!
7463
}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{{!
2+
3+
Copyright (c) Meta Platforms, Inc. and 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+
http://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+
}}{{#type:list?}}{{!
18+
}}<{{!
19+
}}{{#type:list_elem_type}}{{!
20+
}}{{> lib/type}}{{!
21+
}}{{/type:list_elem_type}}{{!
22+
}}>{{!
23+
}}{{/type:list?}}{{!
24+
}}{{#type:set?}}{{!
25+
}}<{{!
26+
}}{{#type:set_elem_type}}{{!
27+
}}{{#type:floating_point?}}::fbthrift::export::OrderedFloat<{{> lib/type}}>{{/type:floating_point?}}{{!
28+
}}{{^type:floating_point?}}{{> lib/type}}{{/type:floating_point?}}{{!
29+
}}{{/type:set_elem_type}}{{!
30+
}}>{{!
31+
}}{{/type:set?}}{{!
32+
}}{{#type:map?}}{{!
33+
}}<{{!
34+
}}{{#type:key_type}}{{!
35+
}}{{#type:floating_point?}}::fbthrift::export::OrderedFloat<{{> lib/type}}>{{/type:floating_point?}}{{!
36+
}}{{^type:floating_point?}}{{> lib/type}}{{/type:floating_point?}}{{!
37+
}}{{/type:key_type}}, {{!
38+
}}{{#type:value_type}}{{!
39+
}}{{> lib/type}}{{!
40+
}}{{/type:value_type}}{{!
41+
}}>{{!
42+
}}{{/type:map?}}{{!
43+
}}

0 commit comments

Comments
 (0)