This is a follow-up to an older post about correct usage of a specific API in the aerospike
crate. It was suggested by @vitalyd that the API could be improved using generic type parameters. I am the maintainer of the aerospike crate and I've been trying to do exactly that.
The existing function I would like to make generic is this:
fn put(&self, policy: &WritePolicy, key: &Key, bins: &[&Bin]) -> Result<()>
I would like to turn this into the following, as suggested:
fn put<I: IntoIterator<Item=A>, A: AsRef<Bin>>(&self, policy: &WritePolicy, key: &Key, bins: I) -> Result<()>
I've pulled out the relevant pieces of the code into this gist (rev 1). The full source code is available in the aerospike-client-rust repo.
I've taken a first stab at making the required changes in rev 2 of the gist.
Now I'm stuck trying to define the generic types for a WriteCommand
struct, which needs to hold the bins
iterator (the result of calling bins.into_iter()
):
pub struct WriteCommand<'a, I: Iterator<Item=A>, A: AsRef<Bin<'a>>> {
bins: I,
}
I am getting the following error:
--> bins.rs:20:25
|
20 | pub struct WriteCommand<'a, I: Iterator<Item=A>, A: AsRef<Bin<'a>>> {
| ^^ unused type parameter
|
= help: consider removing `'a` or using a marker such as `std::marker::PhantomData`
I don't understand this error: I am using the 'a
lifetime, after all. And removing the 'a
type parameter leads to the expected error that 'a
is now undeclared. How do I resolve this?