Skip to content

Commit

Permalink
Result Enum Example Added
Browse files Browse the repository at this point in the history
  • Loading branch information
ramagururadhakrishnan authored May 8, 2024
1 parent 35937bf commit 8eb08ed
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Assets/Lectures/RL5.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
## Lecture 5 - Misc
![](https://img.shields.io/badge/-8th_May-orange)

### Match
```
fn main() {
let number = 13;
Expand Down Expand Up @@ -36,3 +37,24 @@ fn main() {
println!("{} -> {}", boolean, binary);
}
```
### Error - Result Enum
```
fn main() {
// Example of using Result to handle division by zero error
match divide(10.0, 0.0) {
Ok(result) => println!("Result of division: {}", result),
Err(err) => println!("Error: {}", err),
}
}
// Function to divide two numbers
fn divide(x: f64, y: f64) -> Result<f64, &'static str> {
if y == 0.0 {
Err("Division by zero")
} else {
Ok(x / y)
}
}
```


0 comments on commit 8eb08ed

Please sign in to comment.