I was trying to implement an unsized type and realized that Option<T> requires T: Sized. Thinking this was some arbitrary requirement, I tried implementing my own Option and realized that one simply can’t unsize enums. Specifically, I was trying to do the following:
use std::any::Any;
struct Struct<A: ?Sized + Any>(A);
enum Enum<A: ?Sized + Any> {
Some(A),
None,
}
fn main() {
// Works.
let s = Struct(0);
let s = &s as &Struct<Any>;
// Doesn't work (non-scalar cast).
let e = Enum::Some(0);
let e = &e as &Enum<Any>;
}
Can someone explain why I can’t do this?