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 <[email protected]>
  • Loading branch information
wprzytula and Lorak-mmk committed Nov 12, 2024
1 parent 98b382d commit d4a222c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
17 changes: 13 additions & 4 deletions scylla/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,19 @@ pub mod deserialize {

// Shorthands for better readability.
#[cfg_attr(not(test), allow(unused))]
pub(crate) trait DeserializeOwnedValue: for<'r> DeserializeValue<'r, 'r> {}
impl<T> DeserializeOwnedValue for T where T: for<'r> DeserializeValue<'r, 'r> {}
pub(crate) trait DeserializeOwnedRow: for<'r> DeserializeRow<'r, 'r> {}
impl<T> DeserializeOwnedRow for T where T: for<'r> DeserializeRow<'r, 'r> {}
pub(crate) trait DeserializeOwnedValue:
for<'frame, 'metadata> DeserializeValue<'frame, 'metadata>
{
}
impl<T> DeserializeOwnedValue for T where
T: for<'frame, 'metadata> DeserializeValue<'frame, 'metadata>
{
}
pub(crate) trait DeserializeOwnedRow:
for<'frame, 'metadata> DeserializeRow<'frame, 'metadata>
{
}
impl<T> DeserializeOwnedRow for T where T: for<'frame, 'metadata> DeserializeRow<'frame, 'metadata> {}
}

pub mod authentication;
Expand Down
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 d4a222c

Please sign in to comment.