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

5
rust/instances/Cargo.lock generated Normal file
View File

@ -0,0 +1,5 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "rust-oop"
version = "0.1.0"

View File

@ -0,0 +1,9 @@
[package]
name = "rust-oop"
version = "0.1.0"
authors = ["Timo Hocker <t-hocker@web.de>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

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