Run ❯
Get your
own
website
❯
Run Code
Ctrl+Alt+R
Change Orientation
Ctrl+Alt+O
Change Theme
Ctrl+Alt+D
Change Language
Go to Spaces
Ctrl+Alt+P
fn buy(coins: i32, price: i32) -> Result
{ if price > coins { Err(String::from("Not enough coins")) } else { Ok(coins - price) } } fn main() { match buy(100, 30) { Ok(left) => println!("You bought it! Coins left: {}", left), Err(e) => println!("Error: {}", e), } match buy(20, 30) { Ok(left) => println!("You bought it! Coins left: {}", left), Err(e) => println!("Error: {}", e), } }
You bought it! Coins left: 70
Error: Not enough coins