Guest User

borrowed value does not live long enough

a guest
Feb 15th, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 1.36 KB | None | 0 0
  1.     fn convert_result<'a, T: Deserialize<'a>>(&self, result: Result<Iter<Vec<String>>, RedisError>) -> Result<Vec<T>, RepositoryError> {
  2.         match result {
  3.             Ok(iter) =>
  4.                 Ok(iter.flat_map(|s| { s })
  5.                     .collect::<Vec<String>>()
  6.                     .into_iter()
  7.                     .map(|m| serde_json::from_str::<T>(&m).unwrap())
  8.                     .collect()
  9.                 ),
  10.             Err(error) => return Err(
  11.                 RepositoryError::from(
  12.                     ErrorKind::IO, "Could not retrieve data from redis.",
  13.                 )
  14.             )
  15.         }
  16.     }
  17.  
  18. error[E0597]: `m` does not live long enough
  19.   --> src/infrastructure/domain/repository/commons.rs:26:56
  20.    |
  21. 20 |     fn convert_result<'a, T: Deserialize<'a>>(&self, result: Result<Iter<Vec<String>>, RedisError>) -> Result<Vec<T>, RepositoryError> {
  22.    |                       -- lifetime `'a` defined here
  23. ...
  24. 26 |                     .map(|m| serde_json::from_str::<T>(&m).unwrap())
  25.   |                              --------------------------^^-        - `m` dropped here while still borrowed
  26.   |                              |                         |
  27.   |                              |                         borrowed value does not live long enough
  28.   |                              argument requires that `m` is borrowed for `'a`
Add Comment
Please, Sign In to add comment