Я пытаюсь добавить параметр типа C
к этому коду ( детская площадка ):
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]
}
}
Но это приводит к появлению этого сообщения об ошибке:
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
Почему это не разрешено?Connection
является локальным, поэтому согласно объяснению для E0201
кажется, что это не должно приводить к сиротам.