Can trait types be inherited?

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<()>;
}

When I modify the first approach using the solution suggested by the error message, I end up here:

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 as AppointmentT>::ID) -> Result<()>;
}

Awesome, thank you. How did you know you should specify Self:: before A though?

Edit: pardon moi, the A type is not defined, only Self::A is. Thank you, regardless.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.