Skip to content

Commit 499b4f7

Browse files
committed
doc the limits and better error message when it happens.
1 parent 7a11ce0 commit 499b4f7

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/contigous_bitset.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ where
2121
/// The trait bounds on the associated `Int` type allow for the set to convert
2222
/// an `Int` value into a `u64` bit position. All of Rust's integer types of 64
2323
/// bits or less will satisfy the bounds.
24+
///
25+
/// This type only works with Contiguous types where there's 64 or fewer values
26+
/// within the contiguous range. The [new][Self::new] function will just panic
27+
/// when called for a particular type that has too many potential values.
28+
/// Unfortunately, this cannot be computed at compile time because the
29+
/// `C::Int as Into<u64>` implementation can't be called in a `const` context.
2430
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
2531
#[repr(transparent)]
2632
pub struct ContigousBitset64<C>(u64, PhantomData<C>)
@@ -41,10 +47,14 @@ where
4147
/// * `C::MAX_VALUE - C::MIN_VALUE` must be less than 64
4248
#[inline]
4349
#[must_use]
50+
#[track_caller]
4451
pub fn new() -> Self {
4552
let c_max: u64 = C::MAX_VALUE.into();
4653
let c_min: u64 = C::MIN_VALUE.into();
47-
assert!((c_max - c_min) < 64);
54+
assert!(
55+
(c_max - c_min) < 64,
56+
"Contiguous type has more than 64 potential values."
57+
);
4858
Self(0, PhantomData)
4959
}
5060

0 commit comments

Comments
 (0)