Data update
This commit is contained in:
parent
81fd053722
commit
52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions
20
Task/Null-object/Rust/null-object.rs
Normal file
20
Task/Null-object/Rust/null-object.rs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
// If an option may return null - or nothing - in Rust, it's wrapped
|
||||
// in an Optional which may return either the type of object specified
|
||||
// in <> or None. We can check this using .is_some() and .is_none() on
|
||||
// the Option.
|
||||
|
||||
fn check_number(num: &Option<u8>) {
|
||||
if num.is_none() {
|
||||
println!("Number is: None");
|
||||
} else {
|
||||
println!("Number is: {}", num.unwrap());
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut possible_number: Option<u8> = None;
|
||||
check_number(&possible_number);
|
||||
|
||||
possible_number = Some(31);
|
||||
check_number(&possible_number);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue