tuwunel_core/utils/math/expect_into.rs
1/// Converts values through [`TryFrom`] and expects conversion to succeed.
2///
3/// The destination type is selected by the caller or inferred from context.
4/// Conversion failures are treated as violated program invariants.
5pub trait ExpectInto {
6 /// Converts the value into `Dst` and returns the successful result.
7 ///
8 /// The implementation delegates to the shared checked conversion helper. It
9 /// discards the conversion error after using a fixed expectation message.
10 ///
11 /// # Panics
12 ///
13 /// Panics when `Dst::try_from` rejects the source value.
14 #[inline]
15 #[must_use]
16 fn expect_into<Dst: TryFrom<Self>>(self) -> Dst
17 where
18 Self: Sized,
19 {
20 super::expect_into::<Dst, Self>(self)
21 }
22}
23
24impl<T> ExpectInto for T {}