Struct
This commit is contained in:
BIN
BasicSyntax/enum/main.exe
Normal file
BIN
BasicSyntax/enum/main.exe
Normal file
Binary file not shown.
BIN
BasicSyntax/enum/main.pdb
Normal file
BIN
BasicSyntax/enum/main.pdb
Normal file
Binary file not shown.
27
BasicSyntax/enum/main.rs
Normal file
27
BasicSyntax/enum/main.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
enum Color{
|
||||
red(u8),
|
||||
green(u8),
|
||||
blue(u8)
|
||||
}
|
||||
|
||||
fn setcl(color: Color){
|
||||
match color{
|
||||
Color::red(num) => {
|
||||
println!("red oh yeah with num {}", num);
|
||||
},
|
||||
Color::green(num) => {
|
||||
println!("green oh yeah with num {}", num);
|
||||
},
|
||||
Color::blue(num) => {
|
||||
println!("blue oh yeah with num {}", num);
|
||||
}
|
||||
other => {
|
||||
println!("#UNDEFINED");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main(){
|
||||
let a: Color = Color::red(200);
|
||||
setcl(a);
|
||||
}
|
||||
BIN
BasicSyntax/structtest/struct.exe
Normal file
BIN
BasicSyntax/structtest/struct.exe
Normal file
Binary file not shown.
BIN
BasicSyntax/structtest/struct.pdb
Normal file
BIN
BasicSyntax/structtest/struct.pdb
Normal file
Binary file not shown.
31
BasicSyntax/structtest/struct.rs
Normal file
31
BasicSyntax/structtest/struct.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
struct Student{
|
||||
name: String,
|
||||
age: i64,
|
||||
birth: String,
|
||||
score: f64
|
||||
}
|
||||
|
||||
trait make_student{
|
||||
fn get_name(&self) -> &str;
|
||||
|
||||
fn print(&self){
|
||||
println!("{0} is my name, Oh yeah", &self.get_name());
|
||||
}
|
||||
}
|
||||
|
||||
impl make_student for Student{
|
||||
fn get_name(&self) -> &str {
|
||||
return &self.name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fn main(){
|
||||
let s = Student{
|
||||
name: String::from("Van"),
|
||||
age: 19,
|
||||
birth: String::from("2025-09-30"),
|
||||
score: 99.99
|
||||
};
|
||||
s.print();
|
||||
}
|
||||
Reference in New Issue
Block a user