IMHO, Rust just should take size of the largest implementation of Animal for `impl Animal`, and viola — we can make them static. No heap is good for embedded.
Would this not require all impls to be in the same translation unit or the linker has to be explicitly aware of it?
Storing unboxed trait objects in Rust
21–25 of 25 posts
Re: Storing unboxed trait objects in Rust
#22Re: Storing unboxed trait objects in Rust
#23> Rust, not being an object-oriented language, doesn't quite do inheritence like the others. In C++ or Java, subclasses extend superclasses. In Rust, structs implement traits. I wouldn't say that Rust isn't object oriented. It just takes a different approach to some things. Inheritance isn't really a strictly required feature of the object oriented code design. Many for instance pointed out, that composition is prefe…
Rust is clearly not object-oriented. It has very minimal support for late binding, and no support for reflection or dynamic libraries. This isn't a critique, it's just a statement of fact. No Rust designer will say they set out to build a new object-oriented language.
Rust does have some support for reflection, though it is quite limited. https://doc.rust-lang.org/std/any
Re: Storing unboxed trait objects in Rust
#24Earlier quoted context omitted.
Your situation is already sufficiently impossible because it shows that for a given trait, the set of implementors is often (countably) infinite.
However, the number of implementors actually instantiated in any given program is necessarily finite. You could write a program that would make it infinite, e.g. trait Foo { fn foo(); } impl Foo for T { fn foo() { as Foo>::foo(); } } ...but the compiler can't compile it: since Rust implements generics solely through monomorphization, that would require generating an infinitely large binary :)
That doesn't sound right. Trait objects use dynamic dispatch.
Re: Storing unboxed trait objects in Rust
#25> Rust, not being an object-oriented language, doesn't quite do inheritence like the others. In C++ or Java, subclasses extend superclasses. In Rust, structs implement traits. I wouldn't say that Rust isn't object oriented. It just takes a different approach to some things. Inheritance isn't really a strictly required feature of the object oriented code design. Many for instance pointed out, that composition is prefe…
Rust is clearly not object-oriented. It has very minimal support for late binding, and no support for reflection or dynamic libraries. This isn't a critique, it's just a statement of fact. No Rust designer will say they set out to build a new object-oriented language.