有英文版文章
Also this tutorial has been written in English
Check out my Medium
enum Title {
CEO,
CTO,
Engineer
}
struct Employee {
position: Title,
work_hour: i64
}
fn main() {
let person_a = Employee{
position: Title::CTO,
work_hour:25
};
match person_a.position {
Title::CEO => println!("CEO"),
Title::CTO => println!("CTO"),
Title::Engineer => println!("Engineer"),
}
}
/*
CTO
*/
#[derive(Debug)]
enum Title {
CEO,
CTO,
Engineer,
}
struct Employee {
position: Title,
work_hour: i64,
}
fn main() {
let person_a = Employee {
position: Title::CTO,
work_hour: 25,
};
println!("{:?}", person_a.position);
}
/*
CTO
*/
#[derive(Debug)]
enum Title {
CEO,
CTO,
Engineer,
}
#[derive(Debug)]
struct Employee {
position: Title,
work_hour: i64,
}
fn main() {
let person_a = Employee {
position: Title::CTO,
work_hour: 25,
};
println!("{:?}", person_a);
}
/*
Employee { position: CTO, work_hour: 25 }
*/
#[derive(Debug, Clone, Copy)]
enum Title {
CEO,
CTO,
Engineer,
}
#[derive(Debug, Clone, Copy)]
struct Employee {
position: Title,
work_hour: i64,
}
fn print_employee(emp: Employee) {
println!("{:?}", emp);
}
fn main() {
let person_a = Employee {
position: Title::CTO,
work_hour: 25,
};
let person_b = Employee {
position: Title::Engineer,
work_hour: 40,
};
print_employee(person_a);
print_employee(person_b);
}
/*
Employee { position: CTO, work_hour: 25 }
Employee { position: Engineer, work_hour: 40 }
*/
✨參數和引數的差異(Difference between parameter and argument)
✨什麼是過程式程式Procedural programming
void Foo(int i, float f)
{
// Do things
}
void Bar()
{
int num = 1;
Foo(anInt, 2.0);
}