Skip to content

Commit

Permalink
codewide: add #[deprecated] marker for legacy API
Browse files Browse the repository at this point in the history
As we want to phase out the legacy deserialization API, let's yell at
users still using it, by use of the amazing #[deprecated] annotation,
the greatest friend of a Rust lib maintainer.
  • Loading branch information
wprzytula committed Nov 12, 2024
1 parent 07c114e commit bc804e7
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 4 deletions.
10 changes: 10 additions & 0 deletions scylla-cql/src/frame/response/cql_to_rust.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(deprecated)]

use super::result::{CqlValue, Row};
use crate::frame::value::{
Counter, CqlDate, CqlDecimal, CqlDuration, CqlTime, CqlTimestamp, CqlTimeuuid, CqlVarint,
Expand All @@ -19,6 +21,10 @@ pub enum FromRowError {
/// This trait defines a way to convert CqlValue or `Option<CqlValue>` into some rust type
// We can't use From trait because impl From<Option<CqlValue>> for String {...}
// is forbidden since neither From nor String are defined in this crate
#[deprecated(
since = "0.15.0",
note = "Legacy deserialization API is inefficient and is going to be removed soon"
)]
pub trait FromCqlVal<T>: Sized {
fn from_cql(cql_val: T) -> Result<Self, FromCqlValError>;
}
Expand All @@ -34,6 +40,10 @@ pub enum FromCqlValError {
}

/// This trait defines a way to convert CQL Row into some rust type
#[deprecated(
since = "0.15.0",
note = "Legacy deserialization API is inefficient and is going to be removed soon"
)]
pub trait FromRow: Sized {
fn from_row(row: Row) -> Result<Self, FromRowError>;
}
Expand Down
6 changes: 6 additions & 0 deletions scylla-cql/src/frame/response/result.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[allow(deprecated)]
use crate::cql_to_rust::{FromRow, FromRowError};
use crate::frame::frame_errors::{
ColumnSpecParseError, ColumnSpecParseErrorKind, CqlResultParseError, CqlTypeParseError,
Expand Down Expand Up @@ -605,6 +606,11 @@ pub struct Row {

impl Row {
/// Allows converting Row into tuple of rust types or custom struct deriving FromRow
#[deprecated(
since = "0.15.0",
note = "Legacy deserialization API is inefficient and is going to be removed soon"
)]
#[allow(deprecated)]
pub fn into_typed<RowT: FromRow>(self) -> StdResult<RowT, FromRowError> {
RowT::from_row(self)
}
Expand Down
3 changes: 3 additions & 0 deletions scylla-cql/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub mod macros {
// Reexports for derive(IntoUserType)
pub use bytes::{BufMut, Bytes, BytesMut};

#[allow(deprecated)]
pub use crate::impl_from_cql_value_from_method;

pub use crate::impl_serialize_row_via_value_list;
Expand All @@ -22,12 +23,14 @@ pub mod macros {
pub mod types;

pub use crate::frame::response::cql_to_rust;
#[allow(deprecated)]
pub use crate::frame::response::cql_to_rust::FromRow;

pub use crate::frame::types::Consistency;

#[doc(hidden)]
pub mod _macro_internal {
#[allow(deprecated)]
pub use crate::frame::response::cql_to_rust::{
FromCqlVal, FromCqlValError, FromRow, FromRowError,
};
Expand Down
7 changes: 5 additions & 2 deletions scylla/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,16 @@ pub use statement::batch;
pub use statement::prepared_statement;
pub use statement::query;

pub use frame::response::cql_to_rust;
pub use frame::response::cql_to_rust::FromRow;
#[allow(deprecated)]
pub use frame::response::cql_to_rust::{self, FromRow};

#[allow(deprecated)]
pub use transport::caching_session::{CachingSession, GenericCachingSession, LegacyCachingSession};
pub use transport::execution_profile::ExecutionProfile;
#[allow(deprecated)]
pub use transport::legacy_query_result::LegacyQueryResult;
pub use transport::query_result::{QueryResult, QueryRowsResult};
#[allow(deprecated)]
pub use transport::session::{IntoTypedRows, LegacySession, Session, SessionConfig};
pub use transport::session_builder::SessionBuilder;

Expand Down
13 changes: 13 additions & 0 deletions scylla/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
///
/// ---
///
#[deprecated(
since = "0.15.0",
note = "Legacy deserialization API is inefficient and is going to be removed soon"
)]
pub use scylla_cql::macros::FromRow;

/// #[derive(FromUserType)] allows to parse struct as a User Defined Type
Expand All @@ -14,6 +18,10 @@ pub use scylla_cql::macros::FromRow;
///
/// ---
///
#[deprecated(
since = "0.15.0",
note = "Legacy deserialization API is inefficient and is going to be removed soon"
)]
pub use scylla_cql::macros::FromUserType;

/// #[derive(IntoUserType)] allows to pass struct a User Defined Type Value in queries
Expand Down Expand Up @@ -468,6 +476,11 @@ pub use scylla_macros::DeserializeRow;
///
pub use scylla_cql::macros::ValueList;

#[deprecated(
since = "0.15.0",
note = "Legacy deserialization API is inefficient and is going to be removed soon"
)]
#[allow(deprecated)]
pub use scylla_cql::macros::impl_from_cql_value_from_method;

pub use scylla_cql::macros::impl_serialize_row_via_value_list;
Expand Down
17 changes: 16 additions & 1 deletion scylla/src/transport/caching_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ use crate::prepared_statement::PreparedStatement;
use crate::query::Query;
use crate::statement::{PagingState, PagingStateResponse};
use crate::transport::errors::QueryError;
#[allow(deprecated)]
use crate::transport::iterator::LegacyRowIterator;
use crate::transport::partitioner::PartitionerName;
use crate::{LegacyQueryResult, QueryResult};
#[allow(deprecated)]
use crate::LegacyQueryResult;
use crate::QueryResult;
use bytes::Bytes;
use dashmap::DashMap;
use futures::future::try_join_all;
Expand All @@ -17,6 +20,7 @@ use std::hash::BuildHasher;
use std::sync::Arc;

use super::iterator::QueryPager;
#[allow(deprecated)]
use super::session::{
CurrentDeserializationApi, DeserializationApiKind, GenericSession, LegacyDeserializationApi,
};
Expand Down Expand Up @@ -50,6 +54,12 @@ where
}

pub type CachingSession<S = RandomState> = GenericCachingSession<CurrentDeserializationApi, S>;

#[deprecated(
since = "0.15.0",
note = "Legacy deserialization API is inefficient and is going to be removed soon"
)]
#[allow(deprecated)]
pub type LegacyCachingSession<S = RandomState> = GenericCachingSession<LegacyDeserializationApi, S>;

impl<DeserApi, S> GenericCachingSession<DeserApi, S>
Expand Down Expand Up @@ -149,6 +159,11 @@ where
}
}

#[deprecated(
since = "0.15.0",
note = "Legacy deserialization API is inefficient and is going to be removed soon"
)]
#[allow(deprecated)]
impl<S> GenericCachingSession<LegacyDeserializationApi, S>
where
S: BuildHasher + Clone,
Expand Down
17 changes: 17 additions & 0 deletions scylla/src/transport/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use tokio::sync::mpsc;
use super::execution_profile::ExecutionProfileInner;
use super::query_result::ColumnSpecs;
use super::session::RequestSpan;
#[allow(deprecated)]
use crate::cql_to_rust::{FromRow, FromRowError};

use crate::deserialize::DeserializeOwnedRow;
Expand Down Expand Up @@ -675,6 +676,11 @@ impl QueryPager {
/// using the legacy deserialization framework.
/// This is inefficient, because all rows are being eagerly deserialized
/// to a middle-man [Row] type.
#[deprecated(
since = "0.15.0",
note = "Legacy deserialization API is inefficient and is going to be removed soon"
)]
#[allow(deprecated)]
#[inline]
pub fn into_legacy(self) -> LegacyRowIterator {
LegacyRowIterator::new(self)
Expand Down Expand Up @@ -1089,11 +1095,16 @@ where
}

mod legacy {
#![allow(deprecated)]
use super::*;

/// Iterator over rows returned by paged queries.
///
/// Allows to easily access rows without worrying about handling multiple pages.
#[deprecated(
since = "0.15.0",
note = "Legacy deserialization API is inefficient and is going to be removed soon"
)]
pub struct LegacyRowIterator {
raw_stream: QueryPager,
}
Expand Down Expand Up @@ -1142,6 +1153,11 @@ mod legacy {
/// Iterator over rows returned by paged queries
/// where each row is parsed as the given type\
/// Returned by `RowIterator::into_typed`
#[deprecated(
since = "0.15.0",
note = "Legacy deserialization API is inefficient and is going to be removed soon"
)]
#[allow(deprecated)]
pub struct LegacyTypedRowIterator<RowT> {
row_iterator: LegacyRowIterator,
_phantom_data: std::marker::PhantomData<RowT>,
Expand Down Expand Up @@ -1190,4 +1206,5 @@ mod legacy {
// LegacyTypedRowIterator can be moved freely for any RowT so it's Unpin
impl<RowT> Unpin for LegacyTypedRowIterator<RowT> {}
}
#[allow(deprecated)]
pub use legacy::{LegacyRowIterator, LegacyTypedRowIterator, NextRowError};
9 changes: 8 additions & 1 deletion scylla/src/transport/legacy_query_result.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(deprecated)]

use crate::frame::response::cql_to_rust::{FromRow, FromRowError};
use crate::frame::response::result::ColumnSpec;
use crate::frame::response::result::Row;
Expand Down Expand Up @@ -39,7 +41,12 @@ impl<RowT: FromRow> Iterator for TypedRowIter<RowT> {

/// Result of a single query\
/// Contains all rows returned by the database and some more information
#[derive(Debug)]
#[non_exhaustive]
#[derive(Default, Debug)]
#[deprecated(
since = "0.15.0",
note = "Legacy deserialization API is inefficient and is going to be removed soon"
)]
pub struct LegacyQueryResult {
/// Rows returned by the database.\
/// Queries like `SELECT` will have `Some(Vec)`, while queries like `INSERT` will have `None`.\
Expand Down
6 changes: 6 additions & 0 deletions scylla/src/transport/query_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use scylla_cql::types::deserialize::result::TypedRowIterator;
use scylla_cql::types::deserialize::row::DeserializeRow;
use scylla_cql::types::deserialize::{DeserializationError, TypeCheckError};

#[allow(deprecated)]
use super::legacy_query_result::LegacyQueryResult;

/// A view over specification of a table in the database.
Expand Down Expand Up @@ -243,6 +244,11 @@ impl QueryResult {
/// Transforms itself into the legacy result type, by eagerly deserializing rows
/// into the Row type. This is inefficient, and should only be used during transition
/// period to the new API.
#[deprecated(
since = "0.15.0",
note = "Legacy deserialization API is inefficient and is going to be removed soon"
)]
#[allow(deprecated)]
pub fn into_legacy_result(self) -> Result<LegacyQueryResult, RowsParseError> {
if let Some(raw_rows) = self.raw_metadata_and_rows {
let raw_rows_with_metadata = raw_rows.deserialize_metadata()?;
Expand Down
23 changes: 23 additions & 0 deletions scylla/src/transport/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use crate::batch::batch_values;
#[cfg(feature = "cloud")]
use crate::cloud::CloudConfig;
#[allow(deprecated)]
use crate::LegacyQueryResult;

use crate::history;
Expand Down Expand Up @@ -64,6 +65,7 @@ use crate::transport::cluster::{Cluster, ClusterData, ClusterNeatDebug};
use crate::transport::connection::{Connection, ConnectionConfig, VerifiedKeyspaceName};
use crate::transport::connection_pool::PoolConfig;
use crate::transport::host_filter::HostFilter;
#[allow(deprecated)]
use crate::transport::iterator::{LegacyRowIterator, PreparedIteratorConfig};
use crate::transport::load_balancing::{self, RoutingInfo};
use crate::transport::metrics::Metrics;
Expand Down Expand Up @@ -170,8 +172,14 @@ pub enum CurrentDeserializationApi {}
impl sealed::Sealed for CurrentDeserializationApi {}
impl DeserializationApiKind for CurrentDeserializationApi {}

#[deprecated(
since = "0.15.0",
note = "Legacy deserialization API is inefficient and is going to be removed soon"
)]
pub enum LegacyDeserializationApi {}
#[allow(deprecated)]
impl sealed::Sealed for LegacyDeserializationApi {}
#[allow(deprecated)]
impl DeserializationApiKind for LegacyDeserializationApi {}

/// `Session` manages connections to the cluster and allows to perform queries
Expand All @@ -194,6 +202,11 @@ where
}

pub type Session = GenericSession<CurrentDeserializationApi>;
#[allow(deprecated)]
#[deprecated(
since = "0.15.0",
note = "Legacy deserialization API is inefficient and is going to be removed soon"
)]
pub type LegacySession = GenericSession<LegacyDeserializationApi>;

/// This implementation deliberately omits some details from Cluster in order
Expand Down Expand Up @@ -865,6 +878,11 @@ impl GenericSession<CurrentDeserializationApi> {
/// the new API but you still have some modules left that use the old one,
/// you can use this method to create an instance that supports the old API
/// and pass it to the module that you intend to migrate later.
#[deprecated(
since = "0.15.0",
note = "Legacy deserialization API is inefficient and is going to be removed soon"
)]
#[allow(deprecated)]
pub fn make_shared_session_with_legacy_api(&self) -> LegacySession {
LegacySession {
cluster: self.cluster.clone(),
Expand All @@ -884,6 +902,11 @@ impl GenericSession<CurrentDeserializationApi> {
}
}

#[deprecated(
since = "0.15.0",
note = "Legacy deserialization API is inefficient and is going to be removed soon"
)]
#[allow(deprecated)]
impl GenericSession<LegacyDeserializationApi> {
pub async fn query_unpaged(
&self,
Expand Down
6 changes: 6 additions & 0 deletions scylla/src/transport/session_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use super::connection::SelfIdentity;
use super::execution_profile::ExecutionProfileHandle;
#[allow(deprecated)]
use super::session::{
AddressTranslator, CurrentDeserializationApi, GenericSession, LegacyDeserializationApi,
SessionConfig,
Expand Down Expand Up @@ -541,6 +542,11 @@ impl<K: SessionBuilderKind> GenericSessionBuilder<K> {
/// # Ok(())
/// # }
/// ```
#[deprecated(
since = "0.15.0",
note = "Legacy deserialization API is inefficient and is going to be removed soon"
)]
#[allow(deprecated)]
pub async fn build_legacy(
&self,
) -> Result<GenericSession<LegacyDeserializationApi>, NewSessionError> {
Expand Down
1 change: 1 addition & 0 deletions scylla/src/transport/session_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3152,6 +3152,7 @@ async fn test_deserialize_empty_collections() {
}

#[tokio::test]
#[allow(deprecated)]
async fn test_api_migration_session_sharing() {
{
let session = create_new_session_builder().build().await.unwrap();
Expand Down
1 change: 1 addition & 0 deletions scylla/tests/integration/hygiene.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![no_implicit_prelude]
#![allow(deprecated)]

// Macro that is given a crate name and tests it for hygiene
macro_rules! test_crate {
Expand Down

0 comments on commit bc804e7

Please sign in to comment.