Hacker News new | ask | show | jobs
by comex 2741 days ago
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 :)
1 comments

> Rust implements generics solely through monomorphization

That doesn't sound right. Trait objects use dynamic dispatch.