Skip to content

Commit 711a60b

Browse files
committed
Enum Option
1 parent 3ea506a commit 711a60b

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ members = [
1313
"./structs_rectangle",
1414
"./enums",
1515
"./enums_messages",
16+
"./enums_option"
1617
]
1718

enums_option/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "enums_option"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]

enums_option/src/main.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
fn main() {
2+
// T is a 'Generic'. Its type can literally be anything.
3+
// This is just an example of what is already in the standard library.
4+
// It's not really required for the following code
5+
enum Option<T> {
6+
None,
7+
Some(T),
8+
}
9+
10+
// its now an i32
11+
let some_number = Some(5);
12+
// its now a char
13+
let some_char = Some('e');
14+
// its now a string
15+
let some_string = Some(String::from("Hello"));
16+
17+
let nothing: Option<String> = None;
18+
// With Option, we need to define the type when we call 'Some' for example.
19+
}

0 commit comments

Comments
 (0)