Full error:
--> src\readers.rs:10:30
|
5 | pub fn get_sequences(raw_sequences: &str) -> Result<Vec<Cow<[u8]>>, Error> {
| - let's call the lifetime of this reference `'1`
...
10 | while let Some(result) = reader.next() {
| ^^^^^^ `reader` was mutably borrowed here in the previous iteration of the loop
...
15 | Ok(sequences)
| ------------- returning this value requires that `reader` is borrowed for `'1`
Code:
pub fn get_sequences(raw_sequences: &str) -> Result<Vec<Cow<[u8]>>, Error> {
let bytes = raw_sequences.as_bytes();
let mut reader = Reader::new(BufReader::new(bytes));
let mut sequences: Vec<Cow<[u8]>> = vec![];
while let Some(result) = reader.next() {
let record = result?;
sequences.push(record.full_seq());
}
Ok(sequences)
}
I'm using the SeqIO crate (https://github.com/markschl/seq_io/tree/v0.3)
Honestly not sure how to fix this. Any help would be appreciated
full_seq()
doesn't copy the data, it just stores a reference to the reader's buffer, which could become invalid the next time you callreader.next()
, so the compiler won't let you callreader.next()
while that reference still exists. Maybe try usingowned_seq()
instead? That should make an owned copy of the data to store insequences
so that the reader can reuse/overwrite the buffer when you callreader.next()
. – Coder-256