1pub struct U31(u32);
9
10impl U31 {
11 pub const fn new(value: u32) -> Option<Self> {
12 if value > i32::MAX as _ {
13 None
14 } else {
15 Some(Self(value))
16 }
17 }
18}
19
20impl From<U31> for i32 {
21 fn from(value: U31) -> Self {
22 value.0 as _
23 }
24}
25
26pub struct NegativeI32(i32);
28
29impl NegativeI32 {
30 pub const fn new(value: i32) -> Option<Self> {
31 if value < 0 {
32 Some(Self(value))
33 } else {
34 None
35 }
36 }
37}
38
39impl From<NegativeI32> for i32 {
40 fn from(value: NegativeI32) -> Self {
41 value.0
42 }
43}
44
45pub fn fold_into_i32<T, E>(result: Result<T, E>) -> i32
47where
48 T: Into<U31>,
49 E: Into<NegativeI32>,
50{
51 match result {
52 Ok(t) => i32::from(t.into()),
53 Err(e) => i32::from(e.into()),
54 }
55}