More generally, why can’t an enum be dynamically sized?
I ran into this when implementing this set of functions:
trait Foo<T> {
fn f1(self) -> Self;
fn f2(self) -> (T,Self);
fn f3(self) -> Option<Self>;
}
//the trait bound `Self: std::marker::Sized` is not satisfied [E0277]:
//the trait `std::marker::Sized` is not implemented for `Self`
//(consider adding a `where Self: std::marker::Sized` bound,
//required by `std::option::Option`)
Which led me to
enum Bar<T:?Sized> {
None,
Some(T)
//the trait bound `T: std::marker::Sized` is not satisfied [E0277]: the trait `std::marker::Sized`
//is not implemented for `T` (consider adding a `where T: std::marker::Sized` bound, only
// the last field of a struct may have a dynamically sized type)
}
But is there some fundamental reason that an enum can’t consist of a DST, as long as it doesn’t have any other non-zero types? It would seem to be possible for the same reasons that a struct or tuple struct can have a DST as its last item.