Created
August 13, 2021 20:13
-
-
Save Clivern/378d861aab21c726a008e04fa8304ba6 to your computer and use it in GitHub Desktop.
Rust Structs
This file contains hidden or 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
| struct Student { | |
| Name: String, | |
| Age: i16, | |
| } | |
| struct Stud(String, i16); | |
| const JKO: i32 = 3; | |
| enum VehicleType { | |
| BMW, | |
| FIAT, | |
| } | |
| struct Vehicle { | |
| model: VehicleType, | |
| power: i32, | |
| } | |
| fn line() { | |
| println!("LINE------!"); | |
| } | |
| fn main() { | |
| enum Cor { | |
| N, | |
| S, | |
| E, | |
| W, | |
| } | |
| let dir = Cor::N; | |
| println!( | |
| "{}", | |
| match dir { | |
| Cor::N => "N", | |
| _ => "OTHER", | |
| } | |
| ); | |
| println!("Hello, world!"); | |
| for n in 1..20 { | |
| println!( | |
| "{} is {}", | |
| n, | |
| match n { | |
| 1 => "One", | |
| _ if n > 10 => "More Than 10", | |
| _ => "Other", | |
| } | |
| ); | |
| } | |
| let fo: (i32, f32) = (23, 33.33); | |
| println!("{}, {}", fo.0, fo.1); | |
| let mut sex = ("dse", "df", false, 23, 23.33); | |
| sex.0 = "dys"; | |
| println!("{:?}", sex); | |
| let joe = Student { | |
| Name: "Joe".to_string(), | |
| Age: 20, | |
| }; | |
| println!("{:?} - {:?}", joe.Name, joe.Age); | |
| let mut mark = Stud("Mark".to_string(), 30); | |
| mark.1 = 40; | |
| println!("{:?} - {:?}", mark.0, mark.1); | |
| println!("{:?}", JKO); | |
| let vh = Vehicle { | |
| model: VehicleType::FIAT, | |
| power: JKO, | |
| }; | |
| println!("{:?}", vh.power); | |
| match vh.model { | |
| VehicleType::BMW => println!("BMW!"), | |
| _ => println!("OTHER!"), | |
| }; | |
| line(); | |
| line(); | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=378d861aab21c726a008e04fa8304ba6