File tree Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -13,5 +13,6 @@ members = [
13
13
" ./structs_rectangle" ,
14
14
" ./enums" ,
15
15
" ./enums_messages" ,
16
+ " ./enums_option"
16
17
]
17
18
Original file line number Diff line number Diff line change
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 ]
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments