Skip to content

Instantly share code, notes, and snippets.

@Clivern
Created August 13, 2021 20:13
Show Gist options
  • Save Clivern/378d861aab21c726a008e04fa8304ba6 to your computer and use it in GitHub Desktop.
Save Clivern/378d861aab21c726a008e04fa8304ba6 to your computer and use it in GitHub Desktop.
Rust Structs
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();
}
@Clivern
Copy link
Author

Clivern commented Aug 13, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment