Thanks very much for this example. It's the first time I see / have to use Box<Self>
.
It's exactly what I wanted to achieve in my original example.
But after trying some things based on your code, I'm not sure whether (or how) this can help me with my real-world problem.
After some struggles with crates.io and figuring out a publication process, I was finally able to get things published! Here's the full real-life example:
(Documentation doesn't build yet, I'll ask another question in the forum read into this thread on how to fix that.)
My goal is to make this function work with databases that use different types (K
, V
) and constraints (C
):
/// Open databases in environment
///
/// SAFETY: If a database exists already, it must have been created with
/// compatible options.
unsafe fn open_dbs<'a, K, V, C>(
&self,
metas: impl IntoIterator<
IntoIter = impl Iterator<Item = &'a DbOptions<K, V, C, Option<CString>>> + ExactSizeIterator,
>,
) -> Result<Vec<Db<K, V, C>>, io::Error>
where
K: ?Sized + Storable,
V: ?Sized + Storable,
C: Constraint;
I tried to add a trait akin to @quinedot's proposal but ran into some problems when doing so (I think it had to do with having to specify associated types in the functions signature).
If I find time, I'll try to address the issue again and provide more information on where I stumbled.