Skip to content

Commit

Permalink
Merge pull request #38 from jofas/explicitly-cast-macros-keys-also-ca…
Browse files Browse the repository at this point in the history
…sted

Cast keys as well as values for explicitly typed map macros
  • Loading branch information
jofas authored Jan 28, 2024
2 parents 8bc48dd + 18581ed commit ac465a2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* `hashbrown::hash_set` macro

### Changed

* Explicitly typed map macros: keys also cast now (before only values were
casted)

### Removed

* `map` macro
Expand Down
4 changes: 2 additions & 2 deletions src/_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ macro_rules! hash_map {
#[macro_export]
macro_rules! hash_map_e {
{$($k: expr => $v: expr),* $(,)?} => {
::std::collections::HashMap::from([$(($k, $v as _),)*])
::std::collections::HashMap::from([$(($k as _, $v as _),)*])
};
}

Expand Down Expand Up @@ -96,7 +96,7 @@ macro_rules! btree_map {
#[macro_export]
macro_rules! btree_map_e {
{$($k: expr => $v: expr),* $(,)?} => {
::std::collections::BTreeMap::from([$(($k, $v as _),)*])
::std::collections::BTreeMap::from([$(($k as _, $v as _),)*])
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/hashbrown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ macro_rules! __hb_hash_map {
#[macro_export]
macro_rules! __hb_hash_map_e {
{$($k: expr => $v: expr),* $(,)?} => {
<::hashbrown::HashMap::<_, _> as ::core::iter::FromIterator<_>>::from_iter([$(($k, $v as _),)*])
<::hashbrown::HashMap::<_, _> as ::core::iter::FromIterator<_>>::from_iter([$(($k as _, $v as _),)*])
};
}

Expand Down

0 comments on commit ac465a2

Please sign in to comment.