remove duplicate code

This commit is contained in:
2020-05-04 19:34:12 +02:00
parent c6246aade2
commit d30589c5ad
19 changed files with 12 additions and 280 deletions

View File

@ -7,4 +7,4 @@
Relevant Files
- [main.rs](./src/main.rs)
- [main.rs](./classes/src/main.rs)

View File

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

View File

@ -1,9 +0,0 @@
[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]

View File

@ -1,24 +0,0 @@
/*
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

@ -1,23 +0,0 @@
mod car;
use car::Information;
fn main() {
// create a new car and store it in the variable 'a'
// rust also doesn't use the 'new' keyword
// all attributes have to be defined upon creation of the object
let a = car::Car {
// set some data for that car
manufacturer: "Benz".to_string(),
model: "Velo".to_string()
};
// do the same for a second car
let b = car::Car {
manufacturer: "Ford".to_string(),
model: "Model T".to_string()
};
// use a function of the car class to print out the information
a.print_info();
b.print_info();
}