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.

65 lines
1.3 KiB

## easy_traits
### Instructions
2 years ago
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: `. , ? !`
### Expected Function
```rust
2 years ago
#[derive(Clone)]
struct StringValue {
value: String,
}
2 years ago
trait AppendStr {
fn append_str(self, new_str: String) -> Self;
2 years ago
fn append_number(self, new_number: f64) -> Self;
2 years ago
fn remove_punctuation_marks(self) -> Self;
}
impl AppendStr for StringValue {
}
```
### Usage
Here is a program to test your function.
```rust
2 years ago
use easy_traits::*;
fn main() {
2 years ago
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);
2 years ago
str_aux.remove_punctuation_marks();
println!("After removing punctuation: {}", str_aux.value);
}
```
And its output
```console
$ cargo run
2 years ago
Before append: hello
After append: hello there!
After removing punctuation: hello there
$
```