summaryrefslogtreecommitdiff
path: root/exercises/15_traits/traits5.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/traits5.rs
parent77b687d501771c24bd83294d97b8e6f9ffa92d6b (diff)
parent4d9c346a173bb722b929f3ea3c00f84954483e24 (diff)
Merge remote-tracking branch 'upstream/main' into fix-enum-variant-inconsistency
Diffstat (limited to 'exercises/15_traits/traits5.rs')
-rw-r--r--exercises/15_traits/traits5.rs39
1 files changed, 19 insertions, 20 deletions
diff --git a/exercises/15_traits/traits5.rs b/exercises/15_traits/traits5.rs
index df18380..5b356ac 100644
--- a/exercises/15_traits/traits5.rs
+++ b/exercises/15_traits/traits5.rs
@@ -1,40 +1,39 @@
-// traits5.rs
-//
-// Your task is to replace the '??' sections so the code compiles.
-//
-// Don't change any line other than the marked one.
-//
-// Execute `rustlings hint traits5` or use the `hint` watch subcommand for a
-// hint.
-
-// I AM NOT DONE
-
-pub trait SomeTrait {
+trait SomeTrait {
fn some_function(&self) -> bool {
true
}
}
-pub trait OtherTrait {
+trait OtherTrait {
fn other_function(&self) -> bool {
true
}
}
-struct SomeStruct {}
-struct OtherStruct {}
-
+struct SomeStruct;
impl SomeTrait for SomeStruct {}
impl OtherTrait for SomeStruct {}
+
+struct OtherStruct;
impl SomeTrait for OtherStruct {}
impl OtherTrait for OtherStruct {}
-// YOU MAY ONLY CHANGE THE NEXT LINE
-fn some_func(item: ??) -> bool {
+// TODO: Fix the compiler error by only changing the signature of this function.
+fn some_func(item: ???) -> bool {
item.some_function() && item.other_function()
}
fn main() {
- some_func(SomeStruct {});
- some_func(OtherStruct {});
+ // You can optionally experiment here.
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn test_some_func() {
+ assert!(some_func(SomeStruct));
+ assert!(some_func(OtherStruct));
+ }
}