Struct rust_examples::dispatch::CannotMonomorphizeDifferentiableInVecTest [−][src]
pub struct CannotMonomorphizeDifferentiableInVecTest;Expand description
This test shows that if one wants to construct a container (Vec in this case) of Differentiable instances, it cannot be done with a static polymorphic type.
Example
ⓘ
use rust_examples::dispatch::{Differentiable, Trigonometric};
let _: Vec<Differentiable> = vec![Trigonometric::Sine, Trigonometric::Cosine];The size of this heterogeneous container cannot be known at compile time - this issue is that the compiler tries to monomorphize Differentiable items in the Vec but each one might be different and the collection is dynamic, hence the unknown size.
In consequence, here one must use heap-allocated dyn instances (i.e. dynamic dispatch)!
