Skip to content

Commit

Permalink
Allow ui_id!s to seed other ui_id!s
Browse files Browse the repository at this point in the history
The possible `panic` form the `try_from(…).unwrap()` is optimized out for all unsigned types.
  • Loading branch information
bwoods committed Dec 13, 2024
1 parent 8c602fe commit 9c812ed
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions composable-views/src/ui_id/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use syn::parse::Parser;
/// ```
/// use itertools::Itertools;
/// (0..1000)
/// .map(|n| { return ui_id::ui_id!(n) })
/// .collect::<std::vec::Vec<_>>()
/// .map(|n: u32| { return ui_id::ui_id!(n) })
/// .collect::<Vec<_>>()
/// .into_iter()
/// .combinations(2)
/// .into_iter()
Expand All @@ -37,7 +37,7 @@ pub fn ui_id(tokens: proc_macro::TokenStream) -> proc_macro::TokenStream {
// If runtime parameters where passed into the macro, perform a 128-bit FNV-1a
// mix-step to combine them with the current `ui_id` to generate a new one.
let prime = 0x0000000001000000000000000000013Bu128;
#( hash = (hash ^ ((#exprs) as u128)).wrapping_mul(prime); )*
#( hash = (hash ^ u128::try_from(#exprs).unwrap()).wrapping_mul(prime); )*

unsafe { std::num::NonZeroU128::new_unchecked(hash | 0x1u128) }
}
Expand Down

0 comments on commit 9c812ed

Please sign in to comment.