expression
Keep generic helper methods outside the dynamic contract
A trait can contain a generic helper explicitly restricted to Sized implementors while preserving a dyn-compatible callable core. The generic helper is not callable through a trait object. This lets concrete adapters offer useful convenience without requiring the erased interface to support arbitrary type parameters. Expected result (NOT RUN): 3 2 Common mistake: Adding an unrestricted generic method to a trait intended for use through dyn, or attempting to call a Sized-only helper on an erased receiver. Static Rust example; not a verified ByteMind executable assessment.
Formal Syntax & Structure
rust syntaxrust
fn batch<T>(&self, values: &[T]) where Self: SizedWorking Example
Example Snippetrust
trait Output { fn emit(&self, n: usize) -> usize; fn batch<T>(&self, values: &[T]) -> usize where Self: Sized { self.emit(values.len()) }}struct Count;impl Output for Count { fn emit(&self, n: usize) -> usize { n } }fn main() { let count = Count; let port: &dyn Output = &count; println!("{} {}", count.batch(&[1, 2, 3]), port.emit(2));}