Skip to content

Commit 27ce6b5

Browse files
authored
Merge pull request #1122 from wprzytula/delete-lending-stream
iterator: delete `TypedRowLendingStream` as unusable
2 parents 814de55 + f1dc5b6 commit 27ce6b5

File tree

1 file changed

+18
-77
lines changed

1 file changed

+18
-77
lines changed

scylla/src/transport/iterator.rs

Lines changed: 18 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ impl QueryPager {
634634

635635
/// Type-checks the iterator against given type.
636636
///
637-
/// This is automatically called upon transforming [QueryPager] into [TypedRowLendingStream].
637+
/// This is automatically called upon transforming [QueryPager] into [TypedRowStream].
638638
/// Can be used with `next()` for manual deserialization. See `next()` for an example.
639639
#[inline]
640640
pub fn type_check<'frame, 'metadata, RowT: DeserializeRow<'frame, 'metadata>>(
@@ -643,21 +643,6 @@ impl QueryPager {
643643
RowT::type_check(self.column_specs().inner())
644644
}
645645

646-
/// Casts the iterator to a given row type, enabling Stream'ed operations
647-
/// on rows, which deserialize them on-the-fly to that given type.
648-
/// It allows deserializing borrowed types, but hence cannot implement [Stream]
649-
/// (because [Stream] is not lending).
650-
/// Begins with performing type check.
651-
#[inline]
652-
pub fn rows_lending_stream<'frame, 'metadata, RowT: DeserializeRow<'frame, 'metadata>>(
653-
self,
654-
) -> Result<TypedRowLendingStream<RowT>, TypeCheckError>
655-
where
656-
'frame: 'metadata,
657-
{
658-
TypedRowLendingStream::<RowT>::new(self)
659-
}
660-
661646
/// Casts the iterator to a given row type, enabling [Stream]'ed operations
662647
/// on rows, which deserialize them on-the-fly to that given type.
663648
/// It only allows deserializing owned types, because [Stream] is not lending.
@@ -666,9 +651,7 @@ impl QueryPager {
666651
pub fn rows_stream<RowT: 'static + for<'frame, 'metadata> DeserializeRow<'frame, 'metadata>>(
667652
self,
668653
) -> Result<TypedRowStream<RowT>, TypeCheckError> {
669-
TypedRowLendingStream::<RowT>::new(self).map(|typed_row_lending_stream| TypedRowStream {
670-
typed_row_lending_stream,
671-
})
654+
TypedRowStream::<RowT>::new(self)
672655
}
673656

674657
/// Converts this iterator into an iterator over rows parsed as given type,
@@ -982,35 +965,20 @@ impl QueryPager {
982965
}
983966
}
984967

985-
/// Returned by [QueryPager::rows_lending_stream].
968+
/// Returned by [QueryPager::rows_stream].
986969
///
987-
/// Does not implement [Stream], but permits deserialization of borrowed types.
970+
/// Implements [Stream], but only permits deserialization of owned types.
988971
/// To use [Stream] API (only accessible for owned types), use [QueryPager::rows_stream].
989-
pub struct TypedRowLendingStream<RowT> {
972+
pub struct TypedRowStream<RowT: 'static> {
990973
raw_row_lending_stream: QueryPager,
991974
_phantom: std::marker::PhantomData<RowT>,
992975
}
993976

994-
impl<RowT> Unpin for TypedRowLendingStream<RowT> {}
995-
996-
impl<RowT> TypedRowLendingStream<RowT> {
997-
/// If tracing was enabled, returns tracing ids of all finished page queries.
998-
#[inline]
999-
pub fn tracing_ids(&self) -> &[Uuid] {
1000-
self.raw_row_lending_stream.tracing_ids()
1001-
}
1002-
1003-
/// Returns specification of row columns
1004-
#[inline]
1005-
pub fn column_specs(&self) -> ColumnSpecs {
1006-
self.raw_row_lending_stream.column_specs()
1007-
}
1008-
}
977+
impl<RowT> Unpin for TypedRowStream<RowT> {}
1009978

1010-
impl<'frame, 'metadata, RowT> TypedRowLendingStream<RowT>
979+
impl<RowT> TypedRowStream<RowT>
1011980
where
1012-
'frame: 'metadata,
1013-
RowT: DeserializeRow<'frame, 'metadata>,
981+
RowT: for<'frame, 'metadata> DeserializeRow<'frame, 'metadata>,
1014982
{
1015983
fn new(raw_stream: QueryPager) -> Result<Self, TypeCheckError> {
1016984
raw_stream.type_check::<RowT>()?;
@@ -1020,52 +988,19 @@ where
1020988
_phantom: Default::default(),
1021989
})
1022990
}
1023-
1024-
/// Stream-like next() implementation for TypedRowLendingStream.
1025-
///
1026-
/// It also works with borrowed types! For example, &str is supported.
1027-
/// However, this is not a Stream. To create a Stream, use `into_stream()`.
1028-
#[inline]
1029-
pub async fn next(&'frame mut self) -> Option<Result<RowT, QueryError>> {
1030-
self.raw_row_lending_stream.next().await.map(|res| {
1031-
res.and_then(|column_iterator| {
1032-
<RowT as DeserializeRow>::deserialize(column_iterator)
1033-
.map_err(|err| RowsParseError::from(err).into())
1034-
})
1035-
})
1036-
}
1037-
1038-
/// Stream-like try_next() implementation for TypedRowLendingStream.
1039-
///
1040-
/// It also works with borrowed types! For example, &str is supported.
1041-
/// However, this is not a Stream. To create a Stream, use `into_stream()`.
1042-
#[inline]
1043-
pub async fn try_next(&'frame mut self) -> Result<Option<RowT>, QueryError> {
1044-
self.next().await.transpose()
1045-
}
1046-
}
1047-
1048-
/// Returned by [QueryPager::rows_stream].
1049-
///
1050-
/// Implements [Stream], but only permits deserialization of owned types.
1051-
/// To use [Stream] API (only accessible for owned types), use [QueryPager::rows_stream].
1052-
pub struct TypedRowStream<RowT: 'static> {
1053-
typed_row_lending_stream: TypedRowLendingStream<RowT>,
1054991
}
1055992

1056-
impl<RowT> Unpin for TypedRowStream<RowT> {}
1057-
1058993
impl<RowT> TypedRowStream<RowT> {
1059994
/// If tracing was enabled, returns tracing ids of all finished page queries.
1060995
#[inline]
1061996
pub fn tracing_ids(&self) -> &[Uuid] {
1062-
self.typed_row_lending_stream.tracing_ids()
997+
self.raw_row_lending_stream.tracing_ids()
1063998
}
1064999

10651000
/// Returns specification of row columns
10661001
#[inline]
10671002
pub fn column_specs(&self) -> ColumnSpecs {
1068-
self.typed_row_lending_stream.column_specs()
1003+
self.raw_row_lending_stream.column_specs()
10691004
}
10701005
}
10711006

@@ -1079,9 +1014,15 @@ where
10791014
type Item = Result<RowT, QueryError>;
10801015

10811016
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
1082-
let mut s = self.as_mut();
1017+
let next_fut = async {
1018+
self.raw_row_lending_stream.next().await.map(|res| {
1019+
res.and_then(|column_iterator| {
1020+
<RowT as DeserializeRow>::deserialize(column_iterator)
1021+
.map_err(|err| RowsParseError::from(err).into())
1022+
})
1023+
})
1024+
};
10831025

1084-
let next_fut = s.typed_row_lending_stream.next();
10851026
futures::pin_mut!(next_fut);
10861027
let value = ready_some_ok!(next_fut.poll(cx));
10871028
Poll::Ready(Some(Ok(value)))

0 commit comments

Comments
 (0)