instances
This commit is contained in:
5
rust/instances/Cargo.lock
generated
Normal file
5
rust/instances/Cargo.lock
generated
Normal 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"
|
9
rust/instances/Cargo.toml
Normal file
9
rust/instances/Cargo.toml
Normal 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
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