Closed vigna closed 4 weeks ago
Ambassador does support associated types, but they do not need to be specified, e.g.:
use ambassador::{delegatable_trait_remote, Delegate};
use core::ops::Index;
#[derive(Delegate)]
#[delegate(Index<usize>)]
struct Struct(Vec<bool>);
#[delegatable_trait_remote]
pub trait Index<Idx> {
type Output: ?Sized;
fn index(&self, index: Idx) -> &Self::Output;
}
fn main() {
let s = Struct(vec![true, false, true]);
dbg!(&s[1]);
}
I think it would be immensely useful to have these examples in the docs.
Would it work to add a link to https://github.com/hobofan/ambassador/tree/master/ambassador/tests/run-pass somewhere? It includes a lot of examples including associated_types.rs?
Yes, because the tests directory is not where people usually look for documentation. They may look there for examples of usage of a feature once they know about it, but they won't look for features there.
Our last manually delegated trait is
std::ops::Index<usize, Output = bool>
. It appears that ambassador presently does not support associated types. Is this the case?