summaryrefslogtreecommitdiff
path: root/exercises/15_traits/traits1.rs
diff options
context:
space:
mode:
authormo8it <mo8it@proton.me>2024-07-05 13:39:50 +0200
committermo8it <mo8it@proton.me>2024-07-05 13:39:50 +0200
commit7123c7ae3a9605fbe962e4ef0a0f1424cd16fef8 (patch)
treec67f7e62bb9a179ae4fdbab492501cb6847e64c7 /exercises/15_traits/traits1.rs
parent77b687d501771c24bd83294d97b8e6f9ffa92d6b (diff)
parent4d9c346a173bb722b929f3ea3c00f84954483e24 (diff)
Merge remote-tracking branch 'upstream/main' into fix-enum-variant-inconsistency
Diffstat (limited to 'exercises/15_traits/traits1.rs')
-rw-r--r--exercises/15_traits/traits1.rs24
1 files changed, 6 insertions, 18 deletions
diff --git a/exercises/15_traits/traits1.rs b/exercises/15_traits/traits1.rs
index 37dfcbf..85be17e 100644
--- a/exercises/15_traits/traits1.rs
+++ b/exercises/15_traits/traits1.rs
@@ -1,26 +1,17 @@
-// traits1.rs
-//
-// Time to implement some traits! Your task is to implement the trait
-// `AppendBar` for the type `String`. The trait AppendBar has only one function,
-// which appends "Bar" to any object implementing this trait.
-//
-// Execute `rustlings hint traits1` or use the `hint` watch subcommand for a
-// hint.
-
-// I AM NOT DONE
-
+// The trait `AppendBar` has only one function which appends "Bar" to any object
+// implementing this trait.
trait AppendBar {
fn append_bar(self) -> Self;
}
impl AppendBar for String {
- // TODO: Implement `AppendBar` for type `String`.
+ // TODO: Implement `AppendBar` for the type `String`.
}
fn main() {
let s = String::from("Foo");
let s = s.append_bar();
- println!("s: {}", s);
+ println!("s: {s}");
}
#[cfg(test)]
@@ -29,14 +20,11 @@ mod tests {
#[test]
fn is_foo_bar() {
- assert_eq!(String::from("Foo").append_bar(), String::from("FooBar"));
+ assert_eq!(String::from("Foo").append_bar(), "FooBar");
}
#[test]
fn is_bar_bar() {
- assert_eq!(
- String::from("").append_bar().append_bar(),
- String::from("BarBar")
- );
+ assert_eq!(String::from("").append_bar().append_bar(), "BarBar");
}
}