Refactor some_func to accept a generic type implementing SomeTrait and OtherTrait

This commit is contained in:
Rock070 2024-01-03 00:37:32 +08:00
parent 1f926b4358
commit b3fbab1791

View File

@ -7,8 +7,6 @@
// Execute `rustlings hint traits5` or use the `hint` watch subcommand for a
// hint.
// I AM NOT DONE
pub trait SomeTrait {
fn some_function(&self) -> bool {
true
@ -30,7 +28,7 @@ impl SomeTrait for OtherStruct {}
impl OtherTrait for OtherStruct {}
// YOU MAY ONLY CHANGE THE NEXT LINE
fn some_func(item: ??) -> bool {
fn some_func<A: SomeTrait + OtherTrait>(item: A) -> bool {
item.some_function() && item.other_function()
}