mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-01 15:51:12 +00:00
Move stdlib into its own crate
This commit is contained in:
parent
4502d2630f
commit
c7a923d226
11 changed files with 334 additions and 81 deletions
20
stdlib/src/int.rs
Normal file
20
stdlib/src/int.rs
Normal 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!");
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue