Hi,
I’m relatively new to rust and I’m struggling a bit with types an ownership. For back ground I am using rustler to write a nif for Elixir to access the rust aerospike library. (Yeah, I’m in way over my head.) I have the nif mostly working but I’m not sure about one part. The relavant code is:
let mut bins: Vec<&Bin> = Vec::new();
for (k, v) in values {
let s: String = try!(v.decode());
let bin: Bin<'a> = as_bin!(k.decode()?, s);
bins.push(&bin)
}
let res = match client.client.put(&WritePolicy::default(), &key, &bins) {
...
I’m making a vector of references to Bins to pass to put()
. The issue is that the bin is dropped at the end of the for loop so bins.push(&bin)
is an error.
How do I fix this?