instances
This commit is contained in:
24
rust/instances/src/car.rs
Normal file
24
rust/instances/src/car.rs
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
|
||||
Basic Car class
|
||||
just here to make the demonstration in the main file possible
|
||||
explanation of the code here will be given in later lessons
|
||||
|
||||
*/
|
||||
|
||||
pub trait Information {
|
||||
fn print_info(&self);
|
||||
}
|
||||
|
||||
pub struct Car {
|
||||
pub manufacturer: String,
|
||||
pub model: String
|
||||
}
|
||||
|
||||
impl Information for Car {
|
||||
fn print_info(&self) {
|
||||
println!("Car Information:");
|
||||
println!("- manufacturer: {}", self.manufacturer);
|
||||
println!("- model: {}", self.model);
|
||||
}
|
||||
}
|
17
rust/instances/src/main.rs
Normal file
17
rust/instances/src/main.rs
Normal file
@@ -0,0 +1,17 @@
|
||||
mod car;
|
||||
use car::Information;
|
||||
|
||||
fn main() {
|
||||
let a = car::Car {
|
||||
manufacturer: "Benz".to_string(),
|
||||
model: "Velo".to_string()
|
||||
};
|
||||
|
||||
let b = car::Car {
|
||||
manufacturer: "Ford".to_string(),
|
||||
model: "Model T".to_string()
|
||||
};
|
||||
|
||||
a.print_info();
|
||||
b.print_info();
|
||||
}
|
Reference in New Issue
Block a user