Move stdlib into its own crate

This commit is contained in:
Richard Feldman 2019-07-22 22:04:28 -04:00
parent 4502d2630f
commit c7a923d226
11 changed files with 334 additions and 81 deletions

20
stdlib/src/int.rs Normal file
View file

@ -0,0 +1,20 @@
/// 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!");
}