This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
assert_eq!(Some("Andre").unwrap_or("Giant"), "Andre"); // "Andre" | |
assert_eq!(None.unwrap_or("Vizzini"), "Vizzini"); // "Vizzini" | |
//from above | |
assert_eq!(waiting.unwrap_or("Nope"), "I'm Waiting for Vizzini."); // I'm Waiting for Vizzini. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let waiting = Some("I'm Waiting for Vizzini."); | |
//Rust's match statement lets you figure out if you got Some or None | |
match waiting { | |
Some(c) => println!("{}", c), | |
None => println!("You got None"), | |
} | |
Prints "I'm Waiting for Vizzini." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Magician { | |
public Magician(){} | |
public Magician(String name){ | |
this.name = name; | |
} | |
public String getName() { | |
return name; | |
} | |
String name; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Optional of T { | |
None, //There is nothing here. Empty. Nada. | |
Some(T) //We have an item T | |
} | |
//Examples | |
let myOption = Some(5); // Some(int32) | |
let myOption = Some("Rodents of unusual size. I don't believe they exist"); // Some(String) | |
let myOption = None; // We got nothing. |