Browse Source

Merge pull request #1062 from 01-edu/update-description-of-easy_traits-in-01-899

fix easy_traits
pull/1067/head
David Mata 2 years ago committed by GitHub
parent
commit
a9e04d8e88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 49
      subjects/easy_traits/README.md

49
subjects/easy_traits/README.md

@ -2,25 +2,33 @@
### Instructions
Your task is to implement the trait `AppendStr` for the type String, and `AppendVec` for a vector of strings.
Your task is to implement the trait `AppendStr` for the type StringValue.
The trait `AppendStr` has the following functions:
- `append_str`, that appends to the value of the structure a new_str of type String
- `append_number`, that appends to the value of the structure a new_number of type f64
- `remove_punctuation_marks`, that removes from the value of the structure the following punctuation marks: `. , ? !`
The trait `AppendStr` has only one function, which is appending `"world"` to any object implementing this trait.
And `AppendVec` will append `"three"` to a vector of strings.
### Expected Function
```rust
trait AppendStr {
fn append_str(self) -> Self;
#[derive(Clone)]
struct StringValue {
value: String,
}
trait AppendVec {
fn append_vec(&mut self) -> Self;
}
trait AppendStr {
fn append_str(self, new_str: String) -> Self;
impl AppendStr for String {}
fn append_number(self, new_number: f64) -> Self;
impl AppendVec for Vec<String> {}
fn remove_punctuation_marks(self) -> Self;
}
impl AppendStr for StringValue {
}
```
### Usage
@ -28,14 +36,20 @@ impl AppendVec for Vec<String> {}
Here is a program to test your function.
```rust
use easy_traits::easy_traits;
use easy_traits::*;
fn main() {
let s = String::from("hello ").append_str();
println!("{}", s);
let mut str_aux = StringValue {
value: String::from("hello"),
};
println!("Before append: {}", str_aux.value);
str_aux.append_str(String::from(" there!"));
println!("After append: {}", str_aux.value);
let l = vec![String::from("one"), String::from("two")].append_vec();
println!("{:?}", l);
str_aux.remove_punctuation_marks();
println!("After removing punctuation: {}", str_aux.value);
}
```
@ -43,7 +57,8 @@ And its output
```console
$ cargo run
hello world
["one", "two", "three"]
Before append: hello
After append: hello there!
After removing punctuation: hello there
$
```

Loading…
Cancel
Save