Complete trait exercises ()

This commit is contained in:
Tyler Cardinal 2021-05-13 21:40:49 -05:00 committed by GitHub
parent 10dabcd66c
commit 0ed1e16b9c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 6 deletions
exercises/traits

View file

@ -8,14 +8,14 @@
// which appends "Bar" to any object
// implementing this trait.
// I AM NOT DONE
trait AppendBar {
fn append_bar(self) -> Self;
}
impl AppendBar for String {
//Add your code here
fn append_bar(self) -> Self {
format!("{}Bar", self)
}
}
fn main() {

View file

@ -10,13 +10,16 @@
// No boiler plate code this time,
// you can do this!
// I AM NOT DONE
trait AppendBar {
fn append_bar(self) -> Self;
}
//TODO: Add your code here
impl AppendBar for Vec<String> {
fn append_bar(mut self) -> Self {
self.push("Bar".to_string());
self
}
}
#[cfg(test)]
mod tests {