What is the Sized trait

The Sized trait indicates a type has a known size at compile time, which is required for stack allocation and generic parameters by default.

The Sized trait marks types with a known size at compile time, allowing them to be stored directly on the stack. It is implicitly required for all generic type parameters unless explicitly removed with ?Sized.

fn generic<T: Sized>(t: T) {
    // T has a known size at compile time
}

fn generic_maybe_sized<T: ?Sized>(t: &T) {
    // T might be unsized (e.g., str, dyn Trait)
}