You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
davidrobert99 853b793519 uodate rust readme, adding dependencies & clarifications 3 years ago
..
README.md uodate rust readme, adding dependencies & clarifications 3 years ago

README.md

borrow_me_the_reference

Instructions

Ownership is Rust's most unique feature, and it enables Rust to make memory safety guarantees without needing garbage collector. Therefore you must understand ownership in rust.

Create the following functions :

  • delete_and_backspace, imagine that the - represents the backspace key and the + represents the delete key, this function must receive a borrowed string and turn this string into the string that applies the backspaces and the deletes.

  • For example:

    • "helll-o" turns into "hello"

    • "he+lllo" turns into "hello"

  • is_correct that borrows a Vector of string literals with some correct and incorrect math equations and replaces the correct equations with and the wrong with and returns a usize with the percentage of correct equations.

Expected Functions

pub fn delete_and_backspace(s: &mut String) {
}

pub fn is_correct(v: &mut Vec<&str>) -> usize {
}

Notions

Dependencies

meval = "0.2"

Usage

Here is a program to test your function

use borrow_me_the_reference::{delete_and_backspace, is_correct};

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"];

	// - 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

	println!("{:?}", (a, b, per));
	// output: ("borrow", ["✔", "✔", "✘", "✔"], 75)
}

And its output

$ cargo run
("borrow", ["✔", "✔", "✘", "✔"], 75)
$