roc/stdlib/src/int.rs
2019-07-22 22:07:44 -04:00

20 lines
No EOL
359 B
Rust

/// An i64 that always panics on overflow.
pub struct Int(i64);
impl Int {
pub fn abs(&self) -> Self {
let Int(int_self) = self;
let (output, underflowed) = int_self.overflowing_abs();
if underflowed {
underflow_panic();
}
Int(output)
}
}
fn underflow_panic() -> ! {
panic!("Underflow!");
}