Skip to content

Instantly share code, notes, and snippets.

@rrichardson
Last active October 30, 2017 19:21
Show Gist options
  • Save rrichardson/48dc934fe193d2d81baca05958dd5abd to your computer and use it in GitHub Desktop.
Save rrichardson/48dc934fe193d2d81baca05958dd5abd to your computer and use it in GitHub Desktop.
impl<K,T> Set<K,T>
where K : Serialize + DeserializeOwned + Ord + Clone,
T : Serialize + DeserializeOwned + Ord + Clone,
{
pub fn new(db: Arc<DB>, cf: ColumnFamily) -> Set<K,T> {
Set { db, cf, p1: PhantomData, p2: PhantomData }
}
pub fn create<I>(&self, key: &K, values: I, ttl: Option<i64>) -> Result<(), Error>
where for<'a> &'a I: IntoIterator<Item=&'a T> {
let kbuf = serialize(&key, Infinite)?;
let mut vbuf : Vec<u8> = Vec::with_capacity(32);
set_ttl(&mut vbuf, ttl)?;
let val : BTreeSet<&T> = values.into_iter().collect();
serialize_into(&mut vbuf, &val, Infinite).map_err(Error::from)?;
self.db.put_cf(self.cf, kbuf.as_slice(), vbuf.as_slice()).map_err(
Error::from,
)
}
...
}
...
let mut stuff : Vec<String> =
LOREM2.with(|cell| {
let mut chain1 = cell.borrow_mut();
chain1.iter().take(100).map(String::from).collect() });
tbl.create(&key, &stuff, None).unwrap();
error[E0277]: the trait bound `for<'a> &'a &_: std::iter::Iterator` is not satisfied
--> src/lib.rs:453:13
|
453 | tbl.create(&key, &stuff.iter().map(|v| &v).collect(), None).unwrap();
| ^^^^^^ `&'a &_` is not an iterator; maybe try calling `.iter()` or a similar method
|
= help: the trait `for<'a> std::iter::Iterator` is not implemented for `&'a &_`
= note: required because of the requirements on the impl of `for<'a> std::iter::IntoIterator` for `&'a &_`
@rrichardson
Copy link
Author

rrichardson commented Oct 30, 2017

 the parameter type `T` may not live long enough
   --> src/collections.rs:258:5
    |
250 |   impl<K,T> Set<K,T>
    |          - help: consider adding an explicit lifetime bound `T: 'a`...
...
258 | /     pub fn create<'a, I>(&self, key: &K, values: I, ttl: Option<i64>) -> Result<(), Error>
259 | |         where I: IntoIterator<Item=&'a T> {
260 | |         let kbuf = serialize(&key, Infinite)?;
261 | |         let mut vbuf : Vec<u8> = Vec::with_capacity(32);
...   |
267 | |         )
268 | |     }
    | |_____^
    |

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment