Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trait X {
- fn x(&self) -> i32;
- }
- trait Y {
- fn y(&self) -> i32;
- }
- // question: i have implemented X for Y, so
- // shouldn't this mean all instances of Y are
- // also X?
- impl X for Y {
- fn x(&self) -> i32 {
- 123
- }
- }
- // question: here i have a struct Z, and I
- // implement Y for Z, and Y implements X, so
- // shouldn't X by implemented for Z by way of
- // Y?
- struct Z;
- impl Y for Z {
- fn y(&self) -> i32 {
- 0
- }
- }
- fn test(y: Box<dyn Y>) {
- println!("{}", y.x());
- }
- fn main() {
- let z = Box::new(Z);
- test(z);
- }
Add Comment
Please, Sign In to add comment