instances

This commit is contained in:
2020-03-28 14:45:55 +01:00
commit cc9ef0fd57
16 changed files with 254 additions and 0 deletions

24
rust/instances/src/car.rs Normal file
View 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);
}
}

View 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();
}