In this exercise you will create a data model of blood types and an API to deal with blood types
In this exercise you will create a data model of blood types and an API to deal with them.
Start by copying the data representation of the blood types:
Start by copying the data representation of the blood types:
- Create the enumerator `Antigen` that has 4 possibilities: A, B, O and AB And the enumerator `RhFactor` that has two possible values: Positive and Negative
- After, copy the struct BloodType that contains two fields with the names antigen and rh_factor
- Create the enum `Antigen` that has 4 possibilities: A, B, O and AB And the enum `RhFactor` that has two possible values: Positive and Negative
- After, copy the struct `BloodType` that contains two fields with the names antigen and rh_factor
- To provide a simple way to create blood types implement the trait FromStr for BloodType (which will allow us to use the `parse` method and the associated function from_str, so we can do:
- To provide a simple way to create blood types implement the trait FromStr for BloodType (which will allow us to use the `parse` method and the associated function from_str, so we can do:
@ -85,6 +86,8 @@ impl BloodType {
Here is a program to test your function.
Here is a program to test your function.
```rust
```rust
use blood_types::*;
fn main() {
fn main() {
let blood_type: BloodType = "O+".parse().unwrap();
let blood_type: BloodType = "O+".parse().unwrap();
println!("recipients of O+ {:?}", blood_type.recipients());
println!("recipients of O+ {:?}", blood_type.recipients());
In this exercise you will be provided with a json file `commits.json` with data corresponding to git commits in GitHub (extracted using the GitHub rest API), your job is to extract the relevant data and place it in a struct called `CommitData` to get the following information:
In this exercise you will be provided with a json file `commits.json` with data corresponding to git commits in GitHub (extracted using the GitHub rest API). Your objective is to extract the relevant data and place it in a struct called `CommitData` to get the following information:
1. Number of commits per author (identified by the GitHub login).
1. Number of commits per author (identified by the GitHub login).
@ -15,7 +15,7 @@ Create two functions:
- `commits_per_date`: which returns a hash map with the number of commits per week.
- `commits_per_date`: which returns a hash map with the number of commits per week.
- Note: A week is represented by the a year followed by the number of the
- Note: A week is represented by the a year followed by the number of the
week for example January 1, 2020 is in week 1 of 2020 an will be
week. For example, January 1, 2020 is in week 1 of 2020 and will be
Define the function `delete_prefix(prefix, s)`that returns the string slice `s` with the `prefix` removed wrapped in Some. If `prefix ` is not contained in `s` return None
Define the function `delete_prefix(prefix, s)`which returns the string slice `s` with the `prefix` removed wrapped in `Some`. If `prefix ` is not contained in `s`it returns`None`.
You're have to design a notification system for a platform
You have to design a notification system for a platform.
This events can be: Remainders, Registrations, Appointments or Holidays
These events can be: Remainders, Registrations, Appointments or Holidays.
- Create an event handler that depending of the type of event creates different notification: different color, different size and different position
- Create an event handler that, depending on the type of event, creates different notifications with different colors, different sizes and different positions
- The possible positions are Top, Bottom and Center: Create and Enum `Position` with those values
- The possible positions are Top, Bottom and Center: Create and Enum `Position` with those values
@ -42,7 +42,8 @@ This events can be: Remainders, Registrations, Appointments or Holidays
A scalar type must implement the operations Addition, Subtraction, Multiplication and Division (you might also have to use more restrictions). For this use a trait inheritance (supertraits)
Define a `Scalar` trait which must implement the operations Addition, Subtraction, Multiplication and Division (you might also have to use more restrictions). For this use a trait inheritance (supertraits)
Another condition for a number to be a scalar is to have a zero (neutral element in the addition) and a one (neutral element in the multiplication). Therefore the Scalar trait will require 2 functions zero() and one()
Another condition for a number to be a scalar is to have a zero (neutral element in the addition) and a one (neutral element in the multiplication). Therefore the `Scalar` trait will require 2 functions zero() and one() (as shown)
After finishing implement the Scalar trait for u32, u64, i32, i64, f32, f64
After finishing completing the declaration of the trait, implement the `Scalar` trait for u32, u64, i32, i64, f32 and f64.
Create a struct called Person that has two fields: name of type string slice (&str) and age of type u8 and create the associated function new which creates a new person with age 0 and with the name given
Declare the struct called `Person` that has two fields:
### Expected Functions and Data Structures
- name of type string slice (&str)
- age of type u8
Additionaly, create the associated **function**`new` which creates a new person with age 0 and with the name given.
The expected Fucntions and Structures need to be completed.
In this exercise you will define the basic operations with a matrix starting by implementing the `std::ops::Add` trait
In this exercise you will define the basic operations with a matrix starting by implementing the `std::ops::Add` trait
Define the operation + (by defining the trait std::ops::Add) for two matrices remember that two matrices can only be added if they have the same size. Therefore the add method must handle the possibility of failure by returning an Option<T>
Define the operation + (by defining the trait std::ops::Add) for two matrices. Remember that two matrices can only be added if they have the same size. Therefore the add method must handle the possibility of failure by returning an Option<T>.
You will be using your own `Matrix` and `Scalar` defined in the `matrix` and the `lalgebra_scalar` exercises.
### Expected Function
### Expected Function
```rust
```rust
use crate::{Matrix, Scalar};
use std::ops::{ Add, Sub };
use std::ops::{ Add, Sub };
impl Add for Matrix {
impl Add for Matrix {
@ -25,6 +28,8 @@ impl Sub for Matrix {
Here is a program to test your function
Here is a program to test your function
```rust
```rust
use matrix_ops::*;
fn main() {
fn main() {
let matrix = Matrix(vec![vec![8, 1], vec![9, 1]]);
let matrix = Matrix(vec![vec![8, 1], vec![9, 1]]);
let matrix_2 = Matrix(vec![vec![1, 1], vec![1, 1]]);
let matrix_2 = Matrix(vec![vec![1, 1], vec![1, 1]]);
Implement the From<u32> Trait to create a roman number from a u32 the roman number should be in subtractive notation (the common way to write roman number I, II, III, IV, V, VI, VII, VIII, IX, X ...)
Implement the `From<u32> Trait` to create a roman number from a `u32`. The roman number should be in subtractive notation (the common way to write roman number I, II, III, IV, V, VI, VII, VIII, IX, X ...)
For this start by defining the digits as `RomanDigit` with the values I, V, X, L, C, D, M and Nulla for 0
For this start by defining the digits as `RomanDigit` with the values I, V, X, L, C, D, M and Nulla for 0
Next define RomanNumber as a wrapper to a vector of RomanDigit's And implement the Trait From<u32>
Next define `RomanNumber` as a wrapper to a vector of RomanDigit's And implement the Trait `From<u32>`.
### Expected Functions and Data Structures
### Expected Functions and Data Structures
@ -40,6 +41,7 @@ Here is a program to test your function.
Implement the IntoIterator trait for the `RomanNumber` type to enable using a for loop notation. This implementation must allow taking ownership, borrowing and borrowing mutably
Implement the `IntoIterator` trait for the `RomanNumber` type to enable using a for loop notation. This implementation must allow taking ownership, borrowing and borrowing mutably.
1. Taking ownership (this consumes the RomanNumber)
1. Taking ownership (this consumes the RomanNumber)
```rust
```rust
for digit in number {
for digit in number {
...
...
@ -12,6 +13,7 @@ for digit in number {
```
```
2. Borrowing immutably (this preserves the RomanNumber)
2. Borrowing immutably (this preserves the RomanNumber)
```rust
```rust
for digit in &number {
for digit in &number {
@ -19,6 +21,7 @@ for digit in number {
```
```
3. Borrowing mutably (this allow you to modify the RomanNumber without having to return the ownership)
3. Borrowing mutably (this allow you to modify the RomanNumber without having to return the ownership)
Define the structures ThreeDvector that represents a 3 dimensional vector in (for convention in physics the vector are represented as ai + bj + ck where a, b, and c are real numbers and i, j and k represent the direction x,y and z respectively in the Cartesian plane there for we use the names i, j and k for the fields in the ThreeDVector structure
Define the structure`ThreeDvector` that represents a 3 dimensional vector in (for convention in physics the vector are represented as ai + bj + ck where a, b, and c are real numbers and i, j and k represent the direction x,y and z respectively in the Cartesian plane there for we use the names i, j and k for the fields in the ThreeDVector structure
Look how the operations Addition and Subtraction work for a 3 dimensional vector and implement them by implementing the std::ops::Add and std::ops::Sub traits
Look how the operations Addition and Subtraction work for a 3 dimensional vector and implement them by implementing the std::ops::Add and std::ops::Sub traits