mirror of https://github.com/01-edu/public.git
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.
davhojt
c91da2f110
|
2 years ago | |
---|---|---|
.. | ||
README.md | 2 years ago |
README.md
easy_traits
Instructions
Your task is to implement the trait AppendStr
for the type StringValue
.
The trait AppendStr
has the following functions:
append_str
: that appends the string to thevalue
.append_number
: that appends the number to thevalue
.remove_punctuation_marks
: that removes punctuation from thevalue
(.
,,
,?
and!
).
Expected Function
#[derive(Clone)]
struct StringValue {
value: String,
}
trait AppendStr {
fn append_str(self, new_str: String) -> Self;
fn append_number(self, new_number: f64) -> Self;
fn remove_punctuation_marks(self) -> Self;
}
impl AppendStr for StringValue {
}
Usage
Here is a program to test your function.
use easy_traits::*;
fn main() {
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);
str_aux.remove_punctuation_marks();
println!("After removing punctuation: {}", str_aux.value);
}
And its output
$ cargo run
Before append: hello
After append: hello there!
After removing punctuation: hello there
$