Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
### Test Image specific config

FROM rust:1.89-slim-bookworm
FROM rust:1.90-slim-trixie

RUN apt-get update
RUN apt-get -y install pkg-config libssl-dev moreutils
Expand Down
2 changes: 1 addition & 1 deletion solutions/border_cross/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "border_cross"
version = "0.1.0"
authors = ["Augusto <aug.ornelas@gmail.com>"]
edition = "2021"
edition = "2024"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
129 changes: 8 additions & 121 deletions solutions/border_cross/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
// 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
// With the following structure:
#[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,
Expand All @@ -27,135 +19,30 @@ pub trait Vehicle {
}

impl Vehicle for Truck<'_> {
#[inline]
fn model(&self) -> &str {
self.model
}

#[inline]
fn year(&self) -> u32 {
self.year
}
}

impl Vehicle for Car<'_> {
#[inline]
fn model(&self) -> &str {
self.model
}

#[inline]
fn year(&self) -> u32 {
self.year
}
}

// create a function that receives a vector of structures that
// implement the Vehicle trait

#[allow(dead_code)]
pub fn all_models(list: Vec<&dyn Vehicle>) -> Vec<&str> {
let mut models = Vec::new();
for ve in list {
models.push(ve.model());
}
models
}

#[cfg(test)]
mod tests {
use super::*;

fn setup_cars<'a>() -> Vec<&'a dyn Vehicle> {
let cars: Vec<&dyn Vehicle> = vec![
&Car {
plate_nbr: "A3D5C7",
model: "Model 3",
horse_power: 325,
year: 2010,
},
&Car {
plate_nbr: "A785P7",
model: "S",
horse_power: 500,
year: 1980,
},
&Car {
plate_nbr: "D325C7",
model: "300",
horse_power: 300,
year: 2000,
},
&Car {
plate_nbr: "Z3KCH4",
model: "Montana",
horse_power: 325,
year: 2020,
},
];
cars
}

fn setup_trucks<'a>() -> Vec<&'a dyn Vehicle> {
let trucks: Vec<&dyn Vehicle> = vec![
&Truck {
plate_nbr: "V3D5CT",
model: "Ranger",
horse_power: 325,
year: 2010,
load_tons: 40,
},
&Truck {
plate_nbr: "V785PT",
model: "Silverado",
horse_power: 500,
year: 1980,
load_tons: 40,
},
&Truck {
plate_nbr: "DE2SC7",
model: "Sierra",
horse_power: 300,
year: 2000,
load_tons: 40,
},
&Truck {
plate_nbr: "3DH432",
model: "Cybertruck",
horse_power: 325,
year: 2020,
load_tons: 40,
},
];
trucks
}

#[test]
fn all_car_models() {
let cars = setup_cars();
assert_eq!(all_models(cars), ["Model 3", "S", "300", "Montana"]);
}

#[test]
fn all_truck_models() {
let trucks = setup_trucks();
assert_eq!(
all_models(trucks),
["Ranger", "Silverado", "Sierra", "Cybertruck"]
);
}

#[test]
fn cars_and_trucks_models() {
let mut vehicles = setup_cars();
vehicles.extend(setup_trucks());
assert_eq!(
all_models(vehicles),
[
"Model 3",
"S",
"300",
"Montana",
"Ranger",
"Silverado",
"Sierra",
"Cybertruck"
]
);
}
#[inline]
pub fn all_models<const N: usize>(list: [&dyn Vehicle; N]) -> [&str; N] {
list.map(Vehicle::model)
}
2 changes: 1 addition & 1 deletion solutions/delete_prefix/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "delete_prefix"
version = "0.1.0"
authors = ["Augusto <aug.ornelas@gmail.com>"]
edition = "2021"
edition = "2024"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
43 changes: 3 additions & 40 deletions solutions/delete_prefix/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,41 +1,4 @@
// Define the function `delete_prefix(prefix: &str, s: &str) -> Option<&str>`
// That takes 2 slices of string and returns the string of slice s
// with the `prefix` removed wrapped in Some
// If `prefix ` is not contained in `s` return None

// Example:
// delete_prefix("hello, ", "hello, world")? == "world"
// delete_prefix("not", "win");

pub fn delete_prefix<'a, 'b>(prefix: &'b str, s: &'a str) -> Option<&'a str> {
if prefix.len() > s.len() {
return None;
}
let mut char_s = s.chars();

for char_prefix in prefix.chars() {
if char_prefix != char_s.next()? {
return None;
}
}
Some(&s[prefix.len()..])
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_delete_prefix() {
assert_eq!(
delete_prefix("augusto", "augusto ornelas"),
Some(" ornelas")
);

assert_eq!(delete_prefix("ab", "b"), None);

assert_eq!(delete_prefix("aa", "ab"), None);

assert_eq!(delete_prefix("á©", "á©ab"), Some("ab"));
}
#[inline]
pub fn delete_prefix<'a>(prefix: &str, s: &'a str) -> Option<&'a str> {
s.strip_prefix(prefix)
}
5 changes: 2 additions & 3 deletions solutions/events/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
name = "events"
version = "0.1.0"
authors = ["Augusto <aug.ornelas@gmail.com>"]
edition = "2021"
edition = "2024"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
chrono = "0.4"
colored = "2.0.4"
colored = "3.0.0"
Loading
Loading