diff --git a/ts-rs/src/lib.rs b/ts-rs/src/lib.rs index a624cf695..e959cb5f3 100644 --- a/ts-rs/src/lib.rs +++ b/ts-rs/src/lib.rs @@ -104,7 +104,7 @@ //! Implement `TS` for `OrderedFloat` from ordered_float //! //! - `heapless-impl` -//! +//! //! Implement `TS` for `Vec` from heapless //! //! @@ -490,7 +490,7 @@ impl TS for Vec { } } -impl TS for HashMap { +impl TS for HashMap { fn name() -> String { "Record".to_owned() } @@ -579,7 +579,7 @@ impl TS for RangeInclusive { } impl_shadow!(as T: impl<'a, T: TS + ?Sized> TS for &T); -impl_shadow!(as Vec: impl TS for HashSet); +impl_shadow!(as Vec: impl TS for HashSet); impl_shadow!(as Vec: impl TS for BTreeSet); impl_shadow!(as HashMap: impl TS for BTreeMap); impl_shadow!(as Vec: impl TS for [T; N]); diff --git a/ts-rs/tests/hashmap.rs b/ts-rs/tests/hashmap.rs new file mode 100644 index 000000000..a588e9c28 --- /dev/null +++ b/ts-rs/tests/hashmap.rs @@ -0,0 +1,37 @@ +use std::collections::{HashMap, HashSet}; +use ts_rs::TS; + +#[test] +fn hashmap() { + #[derive(TS)] + #[allow(dead_code)] + struct Hashes { + map: HashMap, + set: HashSet, + } + + assert_eq!( + Hashes::decl(), + "type Hashes = { map: Record, set: Array, }" + ) +} + +#[test] +fn hashmap_with_custom_hasher() { + struct CustomHasher {} + + type CustomHashMap = HashMap; + type CustomHashSet = HashSet; + + #[derive(TS)] + #[allow(dead_code)] + struct Hashes { + map: CustomHashMap, + set: CustomHashSet, + } + + assert_eq!( + Hashes::decl(), + "type Hashes = { map: Record, set: Array, }" + ) +}