Last active
August 29, 2015 14:00
-
-
Save zargony/11232547 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn decode<'a, T: Decodable<MyDecoder<BufReader<'a>>, IoError>> (&self, key: u64) -> Result<Option<T>, ~str> { | |
match self.get(key) { | |
Ok(Some(data)) => { | |
let reader = BufReader::new(data); | |
// ^~~~ error: `data` does not live long enough | |
// because 'a is bound to the function context because of the returned T | |
// but 'a actually only needs to be temporary (the reader var in this context) | |
let mut decoder = MyDecoder::new(reader); | |
match Decodable::decode(&mut decoder) { | |
Ok(value) => Ok(Some(value)), | |
Err(err) => Err(format!("deserialize: {}", err)), | |
} | |
}, | |
Ok(None) => Ok(None), | |
Err(err) => Err(err), | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment