Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use impl Future instead of async-trait in most traits #53

Merged
merged 2 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions klickhouse/src/io.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
use crate::{KlickhouseError, Result};
use futures::Future;
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};

use crate::{KlickhouseError, Result};

use crate::protocol::MAX_STRING_SIZE;

#[async_trait::async_trait]
pub trait ClickhouseRead: AsyncRead + Unpin + Send + Sync {
async fn read_var_uint(&mut self) -> Result<u64>;
fn read_var_uint(&mut self) -> impl Future<Output = Result<u64>> + Send;

async fn read_string(&mut self) -> Result<Vec<u8>>;
fn read_string(&mut self) -> impl Future<Output = Result<Vec<u8>>> + Send;

async fn read_utf8_string(&mut self) -> Result<String> {
Ok(String::from_utf8(self.read_string().await?)?)
fn read_utf8_string(&mut self) -> impl Future<Output = Result<String>> + Send {
async { Ok(String::from_utf8(self.read_string().await?)?) }
}
}

#[async_trait::async_trait]
impl<T: AsyncRead + Unpin + Send + Sync> ClickhouseRead for T {
async fn read_var_uint(&mut self) -> Result<u64> {
let mut out = 0u64;
Expand Down Expand Up @@ -50,14 +50,15 @@ impl<T: AsyncRead + Unpin + Send + Sync> ClickhouseRead for T {
}
}

#[async_trait::async_trait]
pub trait ClickhouseWrite: AsyncWrite + Unpin + Send + Sync + 'static {
async fn write_var_uint(&mut self, value: u64) -> Result<()>;
fn write_var_uint(&mut self, value: u64) -> impl Future<Output = Result<()>> + Send;

async fn write_string(&mut self, value: impl AsRef<[u8]> + Send) -> Result<()>;
fn write_string(
&mut self,
value: impl AsRef<[u8]> + Send,
) -> impl Future<Output = Result<()>> + Send;
}

#[async_trait::async_trait]
impl<T: AsyncWrite + Unpin + Send + Sync + 'static> ClickhouseWrite for T {
async fn write_var_uint(&mut self, mut value: u64) -> Result<()> {
for _ in 0..9u64 {
Expand Down
9 changes: 4 additions & 5 deletions klickhouse/src/migrate.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::{query_parser, ClickhouseLock, FromSql};
use async_trait::async_trait;
use refinery_core::traits::r#async::{AsyncMigrate, AsyncQuery, AsyncTransaction};
use refinery_core::Migration;
use std::borrow::Cow;
Expand Down Expand Up @@ -173,7 +172,7 @@ impl Row for Migration {
}
}

#[async_trait]
#[async_trait::async_trait]
impl AsyncTransaction for Client {
type Error = KlickhouseError;

Expand Down Expand Up @@ -206,7 +205,7 @@ impl AsyncTransaction for Client {
}
}

#[async_trait]
#[async_trait::async_trait]
impl AsyncQuery<Vec<Migration>> for Client {
async fn query(
&mut self,
Expand Down Expand Up @@ -248,7 +247,7 @@ impl<T: ClusterName> ClusterMigration<T> {
}
}

#[async_trait]
#[async_trait::async_trait]
impl<T: ClusterName> AsyncTransaction for ClusterMigration<T> {
type Error = KlickhouseError;

Expand Down Expand Up @@ -276,7 +275,7 @@ impl<T: ClusterName> AsyncTransaction for ClusterMigration<T> {
}
}

#[async_trait]
#[async_trait::async_trait]
impl<T: ClusterName> AsyncQuery<Vec<Migration>> for ClusterMigration<T> {
async fn query(
&mut self,
Expand Down
1 change: 0 additions & 1 deletion klickhouse/src/types/deserialize/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ impl ArrayDeserializerGeneric for ArrayDeserializer {
}
}

#[async_trait::async_trait]
impl<T: ArrayDeserializerGeneric + 'static> Deserializer for T {
async fn read_prefix<R: ClickhouseRead>(
type_: &Type,
Expand Down
1 change: 0 additions & 1 deletion klickhouse/src/types/deserialize/geo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::values;

pub struct PointDeserializer;

#[async_trait::async_trait]
impl Deserializer for PointDeserializer {
async fn read_prefix<R: ClickhouseRead>(
_type_: &Type,
Expand Down
1 change: 0 additions & 1 deletion klickhouse/src/types/deserialize/low_cardinality.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use crate::types::low_cardinality::*;

pub struct LowCardinalityDeserializer;

#[async_trait::async_trait]
impl Deserializer for LowCardinalityDeserializer {
async fn read_prefix<R: ClickhouseRead>(
_type_: &Type,
Expand Down
1 change: 0 additions & 1 deletion klickhouse/src/types/deserialize/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use super::{Deserializer, DeserializerState, Type};

pub struct MapDeserializer;

#[async_trait::async_trait]
impl Deserializer for MapDeserializer {
async fn read_prefix<R: ClickhouseRead>(
type_: &Type,
Expand Down
1 change: 0 additions & 1 deletion klickhouse/src/types/deserialize/nullable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use super::{Deserializer, DeserializerState, Type};

pub struct NullableDeserializer;

#[async_trait::async_trait]
impl Deserializer for NullableDeserializer {
async fn read_prefix<R: ClickhouseRead>(
type_: &Type,
Expand Down
1 change: 0 additions & 1 deletion klickhouse/src/types/deserialize/sized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use super::{Deserializer, DeserializerState, Type};

pub struct SizedDeserializer;

#[async_trait::async_trait]
impl Deserializer for SizedDeserializer {
async fn read<R: ClickhouseRead>(
type_: &Type,
Expand Down
1 change: 0 additions & 1 deletion klickhouse/src/types/deserialize/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use super::{Deserializer, DeserializerState, Type};
pub struct StringDeserializer;

#[allow(clippy::uninit_vec)]
#[async_trait::async_trait]
impl Deserializer for StringDeserializer {
async fn read<R: ClickhouseRead>(
type_: &Type,
Expand Down
1 change: 0 additions & 1 deletion klickhouse/src/types/deserialize/tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use super::{Deserializer, DeserializerState, Type};

pub struct TupleDeserializer;

#[async_trait::async_trait]
impl Deserializer for TupleDeserializer {
async fn read_prefix<R: ClickhouseRead>(
type_: &Type,
Expand Down
Loading