From aae6a60036c241a0750423990e357b4646a99ce2 Mon Sep 17 00:00:00 2001 From: Augusto Date: Fri, 19 Mar 2021 23:26:44 +0000 Subject: [PATCH] Found the subject for border_cross --- subjects/border_cross/README.md | 79 +++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 subjects/border_cross/README.md diff --git a/subjects/border_cross/README.md b/subjects/border_cross/README.md new file mode 100644 index 00000000..2a0b329f --- /dev/null +++ b/subjects/border_cross/README.md @@ -0,0 +1,79 @@ +## vehicles + +### Instructions + +- Create the trait Vehicle with the model and year + +- In a border cross you want to keep a list of all the vehicles that are waiting to enter the country. You want to keep a waiting list of the vehicle but the vehicles can be of two types: Car or Truck + +- Create a function that receives a vector of structures that implements the Vehicle trait and returns all the models. + +With the following structure: + +### Expected Functions and Structures + +```rust +#[allow(dead_code)] +pub struct Car<'a> { + pub plate_nbr: &'a str, + pub model: &'a str, + pub horse_power: u32, + pub year: u32, +} + +#[allow(dead_code)] +pub struct Truck<'a> { + pub plate_nbr: &'a str, + pub model: &'a str, + pub horse_power: u32, + pub year: u32, + pub load_tons: u32, +} + +pub trait Vehicle { + fn model(&self) -> &str; + fn year(&self) -> u32; +} + +impl Vehicle for Truck<'_> { +} + +impl Vehicle for Car<'_> { +} + +fn all_models(list: Vec<&Vehicle>) -> Vec<&str> { +} +``` + +### Usage + +Here is a program to test your function. + +```rust +fn main() { + let vehicles: Vec = vec![ + &Car { + plate_nbr: "A3D5C7", + model: "Model 3", + horse_power: 325, + year: 2010, + }, + &Truck { + plate_nbr: "V3D5CT", + model: "Ranger", + horse_power: 325, + year: 2010, + load_tons: 40, + }, + ]; + println!("{:?}", all_models(vehicles)); +} +``` + +And its output + +```console +student@ubuntu:~/[[ROOT]]/test$ cargo run +["Model 3", "Ranger"] +student@ubuntu:~/[[ROOT]]/test$ +```