rustlings/exercises/15_traits/traits5.rs

40 lines
732 B
Rust
Raw Normal View History

2024-05-22 16:04:12 +03:00
trait SomeTrait {
2022-02-25 19:41:36 +03:00
fn some_function(&self) -> bool {
true
}
}
2024-05-22 16:04:12 +03:00
trait OtherTrait {
2022-02-25 19:41:36 +03:00
fn other_function(&self) -> bool {
true
}
}
2024-06-27 13:29:25 +03:00
struct SomeStruct;
2022-02-25 19:41:36 +03:00
impl SomeTrait for SomeStruct {}
impl OtherTrait for SomeStruct {}
2024-06-27 13:29:25 +03:00
struct OtherStruct;
impl SomeTrait for OtherStruct {}
impl OtherTrait for OtherStruct {}
2022-02-25 19:41:36 +03:00
2024-06-27 13:29:25 +03:00
// TODO: Fix the compiler error by only changing the signature of this function.
fn some_func(item: ???) -> bool {
2022-02-25 19:41:36 +03:00
item.some_function() && item.other_function()
}
fn main() {
2024-06-27 13:29:25 +03:00
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_some_func() {
assert!(some_func(SomeStruct));
assert!(some_func(OtherStruct));
}
}