Created
July 29, 2020 22:41
-
-
Save nuttycom/4db37c6d72dcf78319103ecd332e9e4c to your computer and use it in GitHub Desktop.
Error in returning from a function due to a borrowed value.
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
error[E0515]: cannot return value referencing local variable `stmt_blocks` | |
--> zcash_client_sqlite/src/chain.rs:200:9 | |
| | |
194 | let iter = stmt_blocks.query_map(&[from_height.0], |row| { | |
| ----------- `stmt_blocks` is borrowed here | |
... | |
200 | / Ok(Box::new({ | |
201 | | iter.map(|cbr_result| { | |
202 | | let cbr = cbr_result.map_err(Error::from)?; | |
203 | | let block: CompactBlock = parse_from_bytes(&cbr.data).map_err(Error::from)?; | |
... | | |
211 | | }) | |
212 | | })) | |
| |___________^ returns a value referencing data owned by the current function | |
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
pub struct CacheConnection(Connection); | |
impl CacheOps for CacheConnection { | |
type Error = Error; | |
fn fetch_compact_blocks<'a>(&'a self, from_height: &BlockHeight) -> | |
Result<Box<dyn Iterator<Item = Result<CompactBlock, Self::Error>> + 'a>, Self::Error> { | |
let mut stmt_blocks = self.0.prepare("SELECT height, data FROM compactblocks WHERE height > ? ORDER BY height DESC") | |
.map_err(Error::from)?; | |
let iter = stmt_blocks.query_map(&[from_height.0], |row| { | |
let height = row.get(0)?; | |
let data = row.get::<_, Vec<_>>(1)?; | |
Ok(CompactBlockRow { height, data }) | |
}).map_err(Error::from)?; | |
Ok(Box::new({ | |
iter.map(|cbr_result| { | |
let cbr = cbr_result.map_err(Error::from)?; | |
let block: CompactBlock = parse_from_bytes(&cbr.data).map_err(Error::from)?; | |
let row_height = BlockHeight(cbr.height.into()); | |
if block.height() == row_height { | |
Ok(block) | |
} else { | |
Err(ChainInvalid::block_height_mismatch(row_height, block.height())) | |
} | |
}) | |
})) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment