mirror of
https://github.com/ahgamut/rust-ape-example.git
synced 2024-05-29 00:38:05 +00:00
31 lines
560 B
Rust
31 lines
560 B
Rust
|
// ./src/std/panic.md
|
||
|
|
||
|
|
||
|
// Re-implementation of integer division (/)
|
||
|
fn division(dividend: i32, divisor: i32) -> i32 {
|
||
|
if divisor == 0 {
|
||
|
// Division by zero triggers a panic
|
||
|
panic!("division by zero");
|
||
|
} else {
|
||
|
dividend / divisor
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// The `main` task
|
||
|
fn part0() {
|
||
|
// Heap allocated integer
|
||
|
let _x = Box::new(0i32);
|
||
|
|
||
|
// This operation will trigger a task failure
|
||
|
division(3, 0);
|
||
|
|
||
|
println!("This point won't be reached!");
|
||
|
|
||
|
// `_x` should get destroyed at this point
|
||
|
}
|
||
|
|
||
|
pub fn main() {
|
||
|
part0();
|
||
|
}
|
||
|
|