From 33653cebbb192cbed39c3f611e6a86fbe25c03f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Wed, 6 Nov 2024 09:50:38 +0100 Subject: [PATCH] iterator: add test for deserializing borrowed types 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. --- scylla/src/transport/iterator.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/scylla/src/transport/iterator.rs b/scylla/src/transport/iterator.rs index 5bbcb1c533..095e4957df 100644 --- a/scylla/src/transport/iterator.rs +++ b/scylla/src/transport/iterator.rs @@ -1175,3 +1175,29 @@ mod legacy { impl Unpin for LegacyTypedRowIterator {} } 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(); + } + } +}