1
0
Fork 0
mirror of https://github.com/notohh/rustlings.git synced 2024-12-21 07:58:09 -05:00
rustlings/exercises/15_traits/traits5.rs

40 lines
732 B
Rust
Raw Normal View History

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