I'm trying to add the C
type parameter to this code (playground):
use std::ops::Index;
struct ConnectionHandle(usize);
struct Connection<C>(C);
impl<C> Index<ConnectionHandle> for Vec<Connection<C>> {
type Output = Connection<C>;
fn index(&self, ch: ConnectionHandle) -> &Self::Output {
&self[ch.0]
}
}
But doing so causes this error message:
error[E0210]: type parameter `C` must be used as the type parameter for some local type (e.g. `MyStruct<C>`)
--> src/lib.rs:6:1
|
6 | impl<C> Index<ConnectionHandle> for Vec<Connection<C>> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `C` must be used as the type parameter for some local type
|
= note: only traits defined in the current crate can be implemented for a type parameter
Why isn't this allowed? Connection
is local, so per the explanation for E0201
it seems like this should not result in orphans.