rustlings/exercises/15_traits/traits5.rs

40 lines
732 B
Rust
Raw Normal View History

2024-05-22 14:04:12 +01:00
trait SomeTrait {
2022-02-25 16:41:36 +00:00
fn some_function(&self) -> bool {
true
}
}
2024-05-22 14:04:12 +01:00
trait OtherTrait {
2022-02-25 16:41:36 +00:00
fn other_function(&self) -> bool {
true
}
}
2024-06-27 11:29:25 +01:00
struct SomeStruct;
2022-02-25 16:41:36 +00:00
impl SomeTrait for SomeStruct {}
impl OtherTrait for SomeStruct {}
2024-06-27 11:29:25 +01:00
struct OtherStruct;
impl SomeTrait for OtherStruct {}
impl OtherTrait for OtherStruct {}
2022-02-25 16:41:36 +00:00
2024-06-27 11:29:25 +01:00
// TODO: Fix the compiler error by only changing the signature of this function.
fn some_func(item: ???) -> bool {
2022-02-25 16:41:36 +00:00
item.some_function() && item.other_function()
}
fn main() {
2024-06-27 11:29:25 +01: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));
}
}