pub trait Index<Idx: ?Sized> {
type Output: ?Sized;
fn index(&self, index: Idx) -> &Self::Output;
}
When I implement Index
for some type and use ?Sized
because why not
impl<Idx: ?Sized> Index<Idx> for Field {
type Output;
fn index(&self, index: Idx) -> &Self::Output {
todo!()
}
}
I get an error
the size for values of type `Idx` cannot be known at compilation time [E0277]
main.rs(113, 6): this type parameter needs to be `std::marker::Sized`
main.rs(113, 9): consider removing the `?Sized` bound to make the type parameter `Sized`
main.rs(116, 28): function arguments must have a statically known size, borrowed types always have a known size: `&`
So given that arguments must be Sized
, what's the purpose of ?Sized
in Index
?
(Don't know if this really goes in the Help category since this is just me being curious)