From 853b793519bf7a47782ac525041ee966bd11c092 Mon Sep 17 00:00:00 2001 From: davidrobert99 Date: Fri, 4 Mar 2022 16:29:42 +0000 Subject: [PATCH] uodate rust readme, adding dependencies & clarifications --- subjects/borrow_me_the_reference/README.md | 5 +++++ subjects/card_deck/README.md | 3 +++ subjects/circle/README.md | 2 +- subjects/copy/README.md | 8 ++++---- subjects/handling/README.md | 2 +- subjects/hashing/README.md | 2 +- subjects/looping/README.md | 4 ++-- subjects/panic/README.md | 8 ++++++-- subjects/profanity_filter/README.md | 2 +- subjects/tuples/README.md | 6 +++++- 10 files changed, 29 insertions(+), 13 deletions(-) diff --git a/subjects/borrow_me_the_reference/README.md b/subjects/borrow_me_the_reference/README.md index 18724605..ac1ee895 100644 --- a/subjects/borrow_me_the_reference/README.md +++ b/subjects/borrow_me_the_reference/README.md @@ -31,6 +31,11 @@ pub fn is_correct(v: &mut Vec<&str>) -> usize { - [ownership](https://doc.rust-lang.org/book/ch04-00-understanding-ownership.html) - [meval](https://docs.rs/meval/0.2.0/meval/) + +### Dependencies + +meval = "0.2" + ### Usage Here is a program to test your function diff --git a/subjects/card_deck/README.md b/subjects/card_deck/README.md index 850a61bb..cd2494f8 100644 --- a/subjects/card_deck/README.md +++ b/subjects/card_deck/README.md @@ -61,6 +61,9 @@ pub struct Card { pub suit: Suit, pub rank: Rank, } + +pub fn winner_card(car: Card) -> bool{ +} ``` ### Usage diff --git a/subjects/circle/README.md b/subjects/circle/README.md index 9eff933b..b709e49e 100644 --- a/subjects/circle/README.md +++ b/subjects/circle/README.md @@ -28,7 +28,7 @@ Create the structures `Circle` and `Point` (which will be made of two coordinate This snippets are incomplete and it is part of the exercise to discover how to complete them. In the [usage](#usage) you will find all the information that you need. ```rust -struct Circle { +pub struct Circle { center //.. radius //.. } diff --git a/subjects/copy/README.md b/subjects/copy/README.md index 4196039e..b41c1233 100644 --- a/subjects/copy/README.md +++ b/subjects/copy/README.md @@ -25,13 +25,13 @@ The objective is to know how ownership works with different types. ### Expected Functions ```rust -pub fn nbr_function(c: u32) -> (u32, f64, f64) { +pub fn nbr_function(c: i32) -> (i32, f64, f64) { } pub fn str_function(a: String) -> (String, String) { } -pub fn vec_function(b: Vec) -> (Vec, Vec) { +pub fn vec_function(b: Vec) -> (Vec, Vec) { } ``` @@ -43,7 +43,7 @@ Here is a possible program to test your function : use copy::*; fn main() { - let a: u32 = 0; + let a: i32 = 0; let b = String::from("1 2 4 5 6"); let c = vec![1, 2, 4, 5]; @@ -61,7 +61,7 @@ And its output: ```console $ cargo run -(0, 1.0, inf) +(0, 1.0, -inf) ("1 2 4 5 6", "2.718281828459045 7.38905609893065 54.598150033144236 148.4131591025766 403.4287934927351") ([1, 2, 4, 5], [0.0, 0.6931471805599453, 1.3862943611198906, 1.6094379124341003]) $ diff --git a/subjects/handling/README.md b/subjects/handling/README.md index 630de8bc..1573c262 100644 --- a/subjects/handling/README.md +++ b/subjects/handling/README.md @@ -19,7 +19,7 @@ In case something goes wrong, it should panic, with the error. ### Expected Function ```rust -pub fn open_or_create(s: &str, content: &str) { +pub fn open_or_create(file: &str, content: &str) { } ``` diff --git a/subjects/hashing/README.md b/subjects/hashing/README.md index acd4564d..b1495f0f 100644 --- a/subjects/hashing/README.md +++ b/subjects/hashing/README.md @@ -6,7 +6,7 @@ Given a list of integers (Vec) write three **functions**. Write a **function** called `mean` that calculates the `mean` (the average value) of all the values in the list. -Write a **function** called `median` that calculates the `median` (for a sorted list, it is the value in the middle). +Write a **function** called `median` that calculates the `median` (for a sorted list, it is the value in the middle). If there is an even amount of numbers in the list, the middle pair must be determined, added together, and divided by two to find the median value. Write a **function** called `mode` that calculates the mode (the value that appears more often). diff --git a/subjects/looping/README.md b/subjects/looping/README.md index 93d71c33..b183ad80 100644 --- a/subjects/looping/README.md +++ b/subjects/looping/README.md @@ -4,7 +4,7 @@ Write a **program** that prints a riddle, receives input from the user and checks that the answer is correct. -The program must allow indefinite number of trials and only quit after the correct answer is given. +The program must allow an indefinite number of trials and only quit after the correct answer is given. Every time the user introduces an incorrect answer the program must print the riddle again and after the user gives the correct answer the program must print the number of tries that took to get the correct answer. @@ -17,7 +17,7 @@ Answer: The letter e - [Moduler std::io](https://doc.rust-lang.org/std/io/index.html) - [loop](https://doc.rust-lang.org/std/keyword.loop.html) -### Usage +### UsageĀ  ```console $ cargo run diff --git a/subjects/panic/README.md b/subjects/panic/README.md index 58403a39..b9ef0e11 100644 --- a/subjects/panic/README.md +++ b/subjects/panic/README.md @@ -5,8 +5,6 @@ Write a **function** that tries to open a file and panics if the file does not exist. -### Notions - ### Expected Function ```rust @@ -27,9 +25,14 @@ use panic::*; fn main() { let filename = "created.txt"; File::create(filename).unwrap(); + let a = open_file(filename); println!("{:?}", a); + fs::remove_file(filename).unwrap(); + + //It must panic + let b = open_file(filename); } ``` @@ -38,5 +41,6 @@ And its output: ```console $ cargo run File { fd: 3, path: "panic/a.txt", read: true, write: false } +thread 'main' panicked at 'File not found' $ ``` diff --git a/subjects/profanity_filter/README.md b/subjects/profanity_filter/README.md index 078b63da..89e64246 100644 --- a/subjects/profanity_filter/README.md +++ b/subjects/profanity_filter/README.md @@ -18,7 +18,7 @@ The `struct` must also have an implementation of 2 **functions** associated with - `send_ms`, which only has its implementation type (**self**) as argument and returns an option: - This function must return `None` if the content of the message is either **empty** or contains the word **stupid**. Otherwise it returns the content of the message. -You will have to create two more **functions** that are not associated with any structure: +You will have to create one more **function** that is not associated with any structure: - `check_ms` which: - receives as parameters the reference to the structure `Message` diff --git a/subjects/tuples/README.md b/subjects/tuples/README.md index 708f8b72..df8f3f52 100644 --- a/subjects/tuples/README.md +++ b/subjects/tuples/README.md @@ -4,7 +4,7 @@ - Define a tuple structure to represent a `Student`. -- Each student is identified by an id number of type i32, his/her name and his/her last name as a string Print the content of the tuple to stdout +- Each student is identified by an id number of type i32, his/her name and his/her last name of type string. - Then define three **functions** to return the id, first name and last name. @@ -22,6 +22,10 @@ - [Chapter 7](https://doc.rust-lang.org/stable/book/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.html) +### Dependencies + +meval = "0.2" + ### Expected Functions ```rust