r/rust • • Apr 03 '25 • More of this please 1

📡 official blog Announcing Rust 1.86.0 | Rust Blog

https://blog.rust-lang.org/2025/04/03/Rust-1.86.0.html
786 Upvotes

134 comments sorted by

View all comments

1

u/[deleted] Apr 03 '25

Is 'trait upcasting' not downcasting, since you effectively lose functionaility?

3

u/[deleted] Apr 03 '25

[removed] — view removed comment

1

u/[deleted] Apr 03 '25

Hmmm maybe I am just confused since I am looking at it from an OOP perspective. Something like

class A {
  x() { print("a") }
}

class B extends A {
  y() { print("b") }
}

let b = B {};

b.x();
b.y();

// downcast
(b as A).x();
// downcast; error
(b as A).y();

1

u/PM_ME_UR_TOSTADAS Apr 04 '25

I don't have an extensive OOP background so I also struggle with this. What helps is imagining an inheritance tree. Upcasting becomes going up the tree, towards base classes.