linksplatform / doublets-rs

The Unlicense
5 stars 2 forks source link

Use associated types in Doublets trait #5

Open uselessgoddess opened 2 years ago

uselessgoddess commented 2 years ago

Use Doublets<Item = T> instead of Doublets<T>

This is idiomatically more correct. For example – AsRef and Deref:

let string = "hello".to_string();
// we want `AsRef<[u8]>`
let bytes: &[u8] = string.as_ref();
// we want `AsRef<str>`
let str: &str = string.as_ref();
let string = "hello".to_string();
let str = &*string; // we are given `str`

This will also make generic storing doublets than easier.

struct Wrapper<T, D: Doublets<T>> {
    doublets: D,
    _marker: PhantomData<T>,
}
struct Wrapper<D: Doublets> {
    doublets: D,
}
// `T` is `D::Item`