The following throws an error:
Ambiguous Associated Type
pub trait AppointmentT {
type ID;
type Time;
fn id() -> Self::ID;
fn time() -> Self::Time;
}
pub trait AppointmentTrackerT {
type A: AppointmentT;
fn add(&mut self, at: Self::A) -> Result<()>;
fn list<'at>(&self) -> Option<&'at [Self::A]>;
fn next<'at>(&self) -> Option<&'at Self::A>;
fn take(&mut self) -> Option<Self::A>;
fn cancel(id: &Self::A::ID) -> Result<()>; // problem
}
Doing the following gives another error:
Associated Type Bounds Are Unstable
pub trait AppointmentT {
type ID;
type Time;
fn id() -> Self::ID;
fn time() -> Self::Time;
}
pub trait AppointmentTrackerT {
type A: AppointmentT;
fn add(&mut self, at: Self::A) -> Result<()>;
fn list<'at>(&self) -> Option<&'at [Self::A]>;
fn next<'at>(&self) -> Option<&'at Self::A>;
fn take(&mut self) -> Option<Self::A>;
fn cancel(id: &Self::<A: AppointmentT>::ID) -> Result<()>; // an issue as well
}
The following works, but is there a way to avoid re-defining the type without switching to nightly?
Summary
pub trait AppointmentT {
type ID;
type Time;
fn id() -> Self::ID;
fn time() -> Self::Time;
}
pub trait AppointmentTrackerT {
type ID;
type A: AppointmentT;
fn add(&mut self, at: Self::A) -> Result<()>;
fn list<'at>(&self) -> Option<&'at [Self::A]>;
fn next<'at>(&self) -> Option<&'at Self::A>;
fn take(&mut self) -> Option<Self::A>;
fn cancel(id: &Self::ID) -> Result<()>;
}