Re:Storing unboxed trait objects in Rust
by majewsky on Saturday December 15, 2018 @07:13PM
(#18691043)
Your situation is already sufficiently impossible because it shows that for a given trait, the set of implementors is often (countably) infinite.
[ Parent
| on HN ]
Re:Storing unboxed trait objects in Rust
by comex on Saturday December 15, 2018 @07:41PM
(#18691132)
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<T> Foo for T {
fn foo() {
<Box<T> 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 :)
Re:Storing unboxed trait objects in Rust
by oconnor663 on Tuesday December 18, 2018 @01:39PM
(#18709228)
> Rust implements generics solely through monomorphization
That doesn't sound right. Trait objects use dynamic dispatch.