Skip to content

Commit

Permalink
iterator: fix QueryPager::rows_stream() lifetime constraints
Browse files Browse the repository at this point in the history
It appears that the previous requirements:
```rust
fn rows_stream<
    'frame,
    'metadata,
    RowT: 'static + DeserializeRow<'frame, 'metadata>
>
```
allowed creating the `TypedRowStream<&'static str>`. It was error-prone,
because the compiler would accept `rows_stream::<&str>`, happily
deducing that it's `&'static str`, and failing upon Stream `next()` not
being a lending method.

To prevent such situations, the constraints are changed the following
way (credits to @Lorak-mmk):
```rust
fn rows_stream<
    RowT: 'static
          + for<'frame, 'metadata> DeserializeRow<'frame, 'metadata>
>
```
and now `&'static str` is not permitted (because it only implements
`DeserializeValue<'static, '_>`.

Co-authored-by: Karol Baryła <karol.baryla@scylladb.com>
  • Loading branch information
wprzytula and Lorak-mmk committed Nov 12, 2024
1 parent 98b382d commit d342dfe
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions scylla/src/transport/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,12 +663,9 @@ impl QueryPager {
/// It only allows deserializing owned types, because [Stream] is not lending.
/// Begins with performing type check.
#[inline]
pub fn rows_stream<'frame, 'metadata, RowT: 'static + DeserializeRow<'frame, 'metadata>>(
pub fn rows_stream<RowT: 'static + for<'frame, 'metadata> DeserializeRow<'frame, 'metadata>>(
self,
) -> Result<TypedRowStream<RowT>, TypeCheckError>
where
'frame: 'metadata,
{
) -> Result<TypedRowStream<RowT>, TypeCheckError> {
TypedRowLendingStream::<RowT>::new(self).map(|typed_row_lending_stream| TypedRowStream {
typed_row_lending_stream,
})
Expand Down

0 comments on commit d342dfe

Please sign in to comment.