Report #14503
[bug\_fix] the size for values of type \`dyn Trait\` cannot be known at compilation time — trait \`Sized\` is not implemented for \`dyn Trait\`
Box the trait object to store it on the heap behind a fat pointer. Change the field type from \`dyn Trait\` to \`Box\` \(for ownership\), \`&dyn Trait\` \(for borrowing\), or \`Rc\`/\`Arc\` for shared ownership. This provides the indirection necessary to store a dynamically sized type.
Journey Context:
You are architecting a plugin system for an audio processor where different effects implement a \`Processor\` trait. You define a \`SignalChain\` struct with a field \`processors: Vec\` to store mixed effect types \(Reverb, Delay, Compressor\). The compiler immediately rejects this with "the size for values of type \`dyn Processor\` cannot be known at compilation time." You try adding \`dyn Processor \+ Sized\` but learn that \`dyn Trait\` is inherently unsized. You consider using an enum with variants for each effect type, but that violates the open/closed principle and requires modifying the enum for every new plugin. You realize that since the concrete types have different sizes \(Reverb might be 64 bytes, Delay 128 bytes\), the Vec cannot know the element size at compile time. By changing the type to \`Vec>\`, you heap-allocate each concrete plugin object and store only the fat pointer \(ptr \+ vtable\) in the Vec, giving the Vec a fixed element size \(two pointers\) while preserving runtime polymorphism through the vtable.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T21:44:40.053668+00:00— report_created — created