Skip to content

Commit 9bcb6b6

Browse files
authored
Allow any type as the key type in records (#50)
1 parent 943f6d4 commit 9bcb6b6

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/types.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,15 @@ ast_types! {
120120
/// Parses `record<StringType, Type>`
121121
struct RecordType<'a> {
122122
record: term!(record),
123-
generics: Generics<(StringType, term!(,), Box<Type<'a>>)>,
123+
generics: Generics<(Box<RecordKeyType<'a>>, term!(,), Box<Type<'a>>)>,
124124
}
125125

126-
/// Parses one of the string types `ByteString|DOMString|USVString`
127-
#[derive(Copy)]
128-
enum StringType {
126+
/// Parses one of the string types `ByteString|DOMString|USVString` or any other type.
127+
enum RecordKeyType<'a> {
129128
Byte(term!(ByteString)),
130129
DOM(term!(DOMString)),
131130
USV(term!(USVString)),
131+
NonAny(NonAnyType<'a>),
132132
}
133133

134134
/// Parses one of the member of a union type
@@ -242,7 +242,7 @@ mod test {
242242
);
243243

244244
test_variants!(
245-
StringType {
245+
RecordKeyType {
246246
DOM == "DOMString",
247247
USV == "USVString",
248248
Byte == "ByteString"
@@ -254,6 +254,11 @@ mod test {
254254
RecordType;
255255
});
256256

257+
test!(should_parse_record_type_alt_types { "record<u64, short>" =>
258+
"";
259+
RecordType;
260+
});
261+
257262
test!(should_parse_double_type { "double" =>
258263
"";
259264
DoubleType;

0 commit comments

Comments
 (0)