From a1894a816058e978a510429a422050be58af42f1 Mon Sep 17 00:00:00 2001 From: lee Date: Tue, 9 Feb 2021 09:40:40 +0000 Subject: [PATCH] adding "mut" and removing extra exercise --- subjects/name_initials/README.md | 2 +- subjects/string_literal/README.md | 66 ------------------------------ subjects/string_literals/README.md | 15 ++++++- 3 files changed, 15 insertions(+), 68 deletions(-) delete mode 100644 subjects/string_literal/README.md diff --git a/subjects/name_initials/README.md b/subjects/name_initials/README.md index b4f31852..f4a39451 100644 --- a/subjects/name_initials/README.md +++ b/subjects/name_initials/README.md @@ -27,7 +27,7 @@ Here is a program to test your function: use name_initials::initials; fn main() { - let names = vec!["Harry Potter", "Someone Else", "J. L.", "Barack Obama"] + let mut names = vec!["Harry Potter", "Someone Else", "J. L.", "Barack Obama"] println!("{:?}", initials(&mut names)); } ``` diff --git a/subjects/string_literal/README.md b/subjects/string_literal/README.md deleted file mode 100644 index 4641a27c..00000000 --- a/subjects/string_literal/README.md +++ /dev/null @@ -1,66 +0,0 @@ -## string literal - -### Instructions - -Create the following **functions**: - -- `is_empty`, which returns `true` if a string is empty -- `is_ascii`, which returns `true` if all characters of a given string is in ASCII range -- `contains`, which returns `true` if the string contains a given pattern -- `split_at`, which divides a string in two returning a tuple -- `find`, which returns the index if the first character of a given string which matches the pattern - -> This exercise will test the **heap allocation** of your function! -> So try your best to allocate the minimum data on the heap! (hit: &str) - -### Notions - -- https://doc.rust-lang.org/1.22.0/book/first-edition/the-stack-and-the-heap.html -- https://doc.rust-lang.org/rust-by-example/primitives/literals.html - -### Expected Functions - -```rust -fn is_empty(v: &str) -> bool { -} - -fn is_ascii(v: &str) -> bool { -} - -fn contains(v: &str, pat: &str) -> bool { -} - -fn split_at(v: &str, index: usize) -> (&str, &str) { -} - -fn find(v: &str, pat: char) -> usize { -} -``` - -### Usage - -Here is a program to test your function - -```rust -use string_literal::*; - -fn main() { - println!("{}", is_empty("")); - println!("{}", is_ascii("rust")); - println!("{}", contains("rust", "ru")); - println!("{:?}", split_at("rust", 2)); - println!("{}", find("rust", 'u')); -} -``` - -And its output - -```console -student@ubuntu:~/[[ROOT]]/test$ cargo run -true -true -true -("ru", "st") -1 -student@ubuntu:~/[[ROOT]]/test$ -``` diff --git a/subjects/string_literals/README.md b/subjects/string_literals/README.md index ddbf41f7..f159e688 100644 --- a/subjects/string_literals/README.md +++ b/subjects/string_literals/README.md @@ -42,12 +42,25 @@ fn find(v: &str, pat: char) -> usize { Here is a program to test your function ```rust - +use string_literal::*; + +fn main() { + println!("{}", is_empty("")); + println!("{}", is_ascii("rust")); + println!("{}", contains("rust", "ru")); + println!("{:?}", split_at("rust", 2)); + println!("{}", find("rust", 'u')); +} ``` And its output ```console student@ubuntu:~/[[ROOT]]/test$ cargo run +true +true +true +("ru", "st") +1 student@ubuntu:~/[[ROOT]]/test$ ```