Skip to content

Commit

Permalink
iterator: add test for deserializing borrowed types
Browse files Browse the repository at this point in the history
The tests currently fails... see code comment for details.
Therefore, I'm going to remove TypedRowLendingStream altogether. If in
the future we find the solution to make it work, we can extend the API
by adding the `rows_lending_stream` method again. Now we can simply
unpub TypedRowLendingStream and remove `rows_lending_stream` method,
and not mention it in the docs.
This, however, is not a blocker for this PR. Whatever the solution is
going to be (if we find one), it's going to only concern the uppermost
layer of the API, not changing QueryPager at all.

After review of this and gaining acceptance of the reviewer, I'm going
to revert this commit and introduce the above changes.
  • Loading branch information
wprzytula committed Nov 6, 2024
1 parent c76adff commit 33653ce
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions scylla/src/transport/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1175,3 +1175,29 @@ mod legacy {
impl<RowT> Unpin for LegacyTypedRowIterator<RowT> {}
}
pub use legacy::{LegacyRowIterator, LegacyTypedRowIterator, NextRowError};

#[cfg(test)]
mod tests {
use super::*;

// This test would confirm TypedRowLendingStream's power - if it worked...
// The present approach, however, requires borrowing TypedRowLendingStream
// for its whole lifetime (due to `&'a mut T` invariance wrt `T`).
// At the moment, we are unable to work around this problem.
// It would work if `next` method (instead of the TypedRowLendingStream itself)
// was generic over deserialized type, but then we would lose the
// "already type-checked against type T" guarantee embedded in
// `TypedRowLendingStream` type.
async fn _rows_lending_stream_allows_deserializing_borrowed_types() {
// Separate function to hide `unimplemented!()` at the call site from the compiler.
fn create_raw_stream() -> QueryPager {
unimplemented!();
}

let raw_stream: QueryPager = create_raw_stream();
let mut typed = TypedRowLendingStream::new(raw_stream).unwrap();
while let Some(row) = typed.next().await {
let _row: (&str,) = row.unwrap();
}
}
}

0 comments on commit 33653ce

Please sign in to comment.