Browse Source

feat(borrow_me_the_reference): remove need for meval

pull/1541/head
mikysett 2 years ago committed by Michele
parent
commit
1e7ae325ac
  1. 31
      subjects/borrow_me_the_reference/README.md

31
subjects/borrow_me_the_reference/README.md

@ -2,46 +2,40 @@
### Instructions
Ownership is Rust's most unique feature. It enables Rust to make memory safety guarantees without needing a garbage collector. You must have a good understanding of ownership in rust.
> Ownership is Rust's most unique feature. It enables Rust to make memory safety guarantees without needing a garbage collector.
Understanding ownership is essential to take full advantage of Rust capabilities, it influences almost all aspects of the language.
Create the following functions:
- `delete_and_backspace`: which receives a borrowed string, and processes it. `-` represents the backspace key and `+` represents the delete key, so that `"helll-o"` and `"he+lllo"` are both converted to `"hello"`. The `-` and `+` characters should be removed from the string.
- `is_correct`: which borrows a Vector of string literals representing simple addition and subtraction equations. The function should replace the correct equations with `✔`, and the wrong ones with `✘`. It should return a `usize` with the percentage of correct equations.
- `do_operations`: which borrows a Vector of string literals representing simple addition and subtraction equations. The function should replace the operation with the result.
### Expected Functions
```rust
pub fn delete_and_backspace(s: &mut String) {
}
pub fn is_correct(v: &mut Vec<&str>) -> usize {
pub fn do_operations(v: &mut Vec<String>) {
}
```
### Dependencies
meval = "0.2"
### Usage
Here is a program to test your function
```rust
use borrow_me_the_reference::{delete_and_backspace, is_correct};
use borrow_me_the_reference::{delete_and_backspace, do_operations};
fn main() {
let mut a = String::from("bpp--o+er+++sskroi-++lcw");
let mut b: Vec<&str> = vec!["2+2=4", "3+2=5", "10-3=3", "5+5=10"];
let mut b: Vec<String> = vec!["2+2", "3+2", "10-3", "5+5"];
// - If a value does **not implement Copy**, it must be **borrowed** and so will be passed by **reference**.
delete_and_backspace(&mut a); // the reference of the value
let per = is_correct(&mut b); // the reference of the value
delete_and_backspace(&mut a);
do_operations(&mut b);
println!("{:?}", (a, b, per));
// output: ("borrow", ["✔", "✔", "✘", "✔"], 75)
println!("{:?}", (a, b));
}
```
@ -49,11 +43,10 @@ And its output
```console
$ cargo run
("borrow", ["✔", "✔", "✘", "✔"], 75)
("borrow", ["4", "5", "7", "10"])
$
```
### Notions
- [ownership](https://doc.rust-lang.org/book/ch04-00-understanding-ownership.html)
- [meval](https://docs.rs/meval/0.2.0/meval/)
- [Ownership](https://doc.rust-lang.org/book/ch04-00-understanding-ownership.html)

Loading…
Cancel
Save