Skip to content

Commit

Permalink
codewide: deprecate legacy deserialization API's unmarked remnants
Browse files Browse the repository at this point in the history
There were some remnants from the legacy deserialization API that had
not been marked with #[deprecated] attribute.
  • Loading branch information
wprzytula committed Dec 6, 2024
1 parent 4b6ad84 commit a3a0d69
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 5 deletions.
13 changes: 13 additions & 0 deletions scylla-cql/src/frame/response/cql_to_rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ use std::net::IpAddr;
use thiserror::Error;
use uuid::Uuid;

#[deprecated(
since = "0.15.1",
note = "Legacy deserialization API is inefficient and is going to be removed soon"
)]
#[allow(deprecated)]
#[derive(Error, Debug, Clone, PartialEq, Eq)]
pub enum FromRowError {
#[error("{err} in the column with index {column}")]
Expand All @@ -29,6 +34,10 @@ pub trait FromCqlVal<T>: Sized {
fn from_cql(cql_val: T) -> Result<Self, FromCqlValError>;
}

#[deprecated(
since = "0.15.1",
note = "Legacy deserialization API is inefficient and is going to be removed soon"
)]
#[derive(Error, Debug, Clone, PartialEq, Eq)]
pub enum FromCqlValError {
#[error("Bad CQL type")]
Expand Down Expand Up @@ -99,6 +108,10 @@ impl<T: FromCqlVal<CqlValue>> FromCqlVal<Option<CqlValue>> for Option<T> {
///
/// impl_from_cql_value_from_method!(MyBytes, into_my_bytes);
/// ```
#[deprecated(
since = "0.15.1",
note = "Legacy deserialization API is inefficient and is going to be removed soon"
)]
#[macro_export]
macro_rules! impl_from_cql_value_from_method {
($T:ty, $convert_func:ident) => {
Expand Down
26 changes: 21 additions & 5 deletions scylla/src/transport/errors.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
//! This module contains various errors which can be returned by [`Session`](crate::transport::session::Session).
// I did not manage to silence deprecation warnings without using this module-wide.
// TODO: remove this once deprecated items are no longer used here.
#![allow(deprecated)]

// Re-export DbError type and types that it depends on
// so they can be found in `scylla::errors`.
pub use scylla_cql::frame::response::error::{DbError, OperationType, WriteType};
Expand Down Expand Up @@ -34,15 +38,15 @@ use thiserror::Error;

use crate::{authentication::AuthError, frame::response};

use super::{
iterator::NextRowError,
legacy_query_result::IntoLegacyQueryResultError,
query_result::{IntoRowsResultError, SingleRowError},
};
use super::iterator::NextRowError;
#[allow(deprecated)]
use super::legacy_query_result::IntoLegacyQueryResultError;
use super::query_result::{IntoRowsResultError, SingleRowError};

/// Error that occurred during query execution
#[derive(Error, Debug, Clone)]
#[non_exhaustive]
#[allow(deprecated)]
pub enum QueryError {
/// Database sent a response containing some error with a message
#[error("Database returned an error: {0}, Error message: {1}")]
Expand Down Expand Up @@ -115,6 +119,11 @@ pub enum QueryError {

/// Failed to convert [`QueryResult`][crate::transport::query_result::QueryResult]
/// into [`LegacyQueryResult`][crate::transport::legacy_query_result::LegacyQueryResult].
#[deprecated(
since = "0.15.1",
note = "Legacy deserialization API is inefficient and is going to be removed soon"
)]
#[allow(deprecated)]
#[error("Failed to convert `QueryResult` into `LegacyQueryResult`: {0}")]
IntoLegacyQueryResultError(#[from] IntoLegacyQueryResultError),
}
Expand Down Expand Up @@ -181,6 +190,7 @@ impl From<QueryError> for NewSessionError {
QueryError::BrokenConnection(e) => NewSessionError::BrokenConnection(e),
QueryError::UnableToAllocStreamId => NewSessionError::UnableToAllocStreamId,
QueryError::RequestTimeout(msg) => NewSessionError::RequestTimeout(msg),
#[allow(deprecated)]
QueryError::IntoLegacyQueryResultError(e) => {
NewSessionError::IntoLegacyQueryResultError(e)
}
Expand All @@ -204,6 +214,7 @@ impl From<response::Error> for QueryError {
/// Error that occurred during session creation
#[derive(Error, Debug, Clone)]
#[non_exhaustive]
#[allow(deprecated)]
pub enum NewSessionError {
/// Failed to resolve hostname passed in Session creation
#[error("Couldn't resolve any hostname: {0:?}")]
Expand Down Expand Up @@ -286,6 +297,11 @@ pub enum NewSessionError {

/// Failed to convert [`QueryResult`][crate::transport::query_result::QueryResult]
/// into [`LegacyQueryResult`][crate::transport::legacy_query_result::LegacyQueryResult].
#[deprecated(
since = "0.15.1",
note = "Legacy deserialization API is inefficient and is going to be removed soon"
)]
#[allow(deprecated)]
#[error("Failed to convert `QueryResult` into `LegacyQueryResult`: {0}")]
IntoLegacyQueryResultError(#[from] IntoLegacyQueryResultError),
}
Expand Down
4 changes: 4 additions & 0 deletions scylla/src/transport/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,10 @@ mod legacy {
}

/// Couldn't get next typed row from the iterator
#[deprecated(
since = "0.15.1",
note = "Legacy deserialization API is inefficient and is going to be removed soon"
)]
#[derive(Error, Debug, Clone)]
pub enum LegacyNextRowError {
/// Query to fetch next page has failed
Expand Down
33 changes: 33 additions & 0 deletions scylla/src/transport/legacy_query_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ use uuid::Uuid;

/// Trait used to implement `Vec<result::Row>::into_typed<RowT>`
// This is the only way to add custom method to Vec
#[deprecated(
since = "0.15.1",
note = "Legacy deserialization API is inefficient and is going to be removed soon"
)]
#[allow(deprecated)]
pub trait IntoTypedRows {
fn into_typed<RowT: FromRow>(self) -> TypedRowIter<RowT>;
}
Expand All @@ -28,6 +33,10 @@ impl IntoTypedRows for Vec<result::Row> {

/// Iterator over rows parsed as the given type\
/// Returned by `rows.into_typed::<(...)>()`
#[deprecated(
since = "0.15.1",
note = "Legacy deserialization API is inefficient and is going to be removed soon"
)]
pub struct TypedRowIter<RowT: FromRow> {
row_iter: std::vec::IntoIter<result::Row>,
phantom_data: std::marker::PhantomData<RowT>,
Expand Down Expand Up @@ -185,6 +194,10 @@ impl LegacyQueryResult {

/// An error that occurred during [`QueryResult`](crate::transport::query_result::QueryResult)
/// to [`LegacyQueryResult`] conversion.
#[deprecated(
since = "0.15.1",
note = "Legacy deserialization API is inefficient and is going to be removed soon"
)]
#[non_exhaustive]
#[derive(Error, Clone, Debug)]
pub enum IntoLegacyQueryResultError {
Expand All @@ -205,6 +218,11 @@ pub enum IntoLegacyQueryResultError {
/// Expected `LegacyQueryResult.rows` to be `Some`, but it was `None`.\
/// `LegacyQueryResult.rows` is `Some` for queries that can return rows (e.g `SELECT`).\
/// It is `None` for queries that can't return rows (e.g `INSERT`).
#[deprecated(
since = "0.15.1",
note = "Legacy deserialization API is inefficient and is going to be removed soon"
)]
#[allow(deprecated)]
#[derive(Debug, Clone, Error, PartialEq, Eq)]
#[error(
"LegacyQueryResult::rows() or similar function called on a bad LegacyQueryResult.
Expand Down Expand Up @@ -259,6 +277,11 @@ pub enum FirstRowTypedError {
FromRowError(#[from] FromRowError),
}

#[deprecated(
since = "0.15.1",
note = "Legacy deserialization API is inefficient and is going to be removed soon"
)]
#[allow(deprecated)]
#[derive(Debug, Clone, Error, PartialEq, Eq)]
pub enum MaybeFirstRowTypedError {
/// [`LegacyQueryResult::maybe_first_row_typed()`](LegacyQueryResult::maybe_first_row_typed) called on a bad LegacyQueryResult.\
Expand All @@ -273,6 +296,11 @@ pub enum MaybeFirstRowTypedError {
FromRowError(#[from] FromRowError),
}

#[deprecated(
since = "0.15.1",
note = "Legacy deserialization API is inefficient and is going to be removed soon"
)]
#[allow(deprecated)]
#[derive(Debug, Clone, Error, PartialEq, Eq)]
pub enum SingleRowError {
/// [`LegacyQueryResult::single_row()`](LegacyQueryResult::single_row) called on a bad LegacyQueryResult.\
Expand All @@ -287,6 +315,11 @@ pub enum SingleRowError {
BadNumberOfRows(usize),
}

#[deprecated(
since = "0.15.1",
note = "Legacy deserialization API is inefficient and is going to be removed soon"
)]
#[allow(deprecated)]
#[derive(Debug, Clone, Error, PartialEq, Eq)]
pub enum SingleRowTypedError {
/// [`LegacyQueryResult::single_row_typed()`](LegacyQueryResult::single_row_typed) called on a bad LegacyQueryResult.\
Expand Down
1 change: 1 addition & 0 deletions scylla/src/transport/load_balancing/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2853,6 +2853,7 @@ mod latency_awareness {
| QueryError::DbError(DbError::RateLimitReached { .. }, _) => false,

// "slow" errors, i.e. ones that are returned after considerable time of query being run
#[allow(deprecated)]
QueryError::DbError(_, _)
| QueryError::CqlResultParseError(_)
| QueryError::CqlErrorParseError(_)
Expand Down
1 change: 1 addition & 0 deletions scylla/src/transport/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ pub use crate::transport::connection_pool::PoolSize;

// This re-export is to preserve backward compatibility.
// Those items are no longer here not to clutter session.rs with legacy things.
#[allow(deprecated)]
pub use crate::transport::legacy_query_result::{IntoTypedRows, TypedRowIter};

use crate::authentication::AuthenticatorProvider;
Expand Down
1 change: 1 addition & 0 deletions scylla/src/transport/speculative_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ fn can_be_ignored<ResT>(result: &Result<ResT, QueryError>) -> bool {
QueryError::EmptyPlan => false,

// Errors that should not appear here, thus should not be ignored
#[allow(deprecated)]
QueryError::NextRowError(_)
| QueryError::IntoLegacyQueryResultError(_)
| QueryError::TimeoutError
Expand Down

0 comments on commit a3a0d69

Please sign in to comment.