Skip to content

Commit

Permalink
Add Send + Sync boundaries for parameters
Browse files Browse the repository at this point in the history
Helps with spawning code.
  • Loading branch information
Julius de Bruijn committed May 25, 2020
1 parent ec7f8e3 commit 1e65704
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/result.rs
Expand Up @@ -77,7 +77,7 @@ pub struct QueryResult<'a> {

impl<'a> QueryResult<'a> {
pub(crate) fn new(
token_stream: Pin<Box<dyn Stream<Item = crate::Result<ReceivedToken>> + 'a>>,
token_stream: Pin<Box<dyn Stream<Item = crate::Result<ReceivedToken>> + Send + 'a>>,
) -> Self {
let stream = QueryStream::new(token_stream);

Expand Down
4 changes: 2 additions & 2 deletions src/tds/codec/token/token_env_change.rs
Expand Up @@ -35,8 +35,8 @@ uint_enum! {
}

pub struct CollationInfo {
lcid_encoding: Option<&'static dyn Encoding>,
sortid_encoding: Option<&'static dyn Encoding>,
lcid_encoding: Option<&'static (dyn Encoding + Send + Sync)>,
sortid_encoding: Option<&'static (dyn Encoding + Send + Sync)>,
}

impl CollationInfo {
Expand Down
6 changes: 3 additions & 3 deletions src/tds/collation.rs
Expand Up @@ -26,7 +26,7 @@ impl Collation {
}

/// return an encoding for a given collation
pub fn encoding(&self) -> Option<&'static dyn Encoding> {
pub fn encoding(&self) -> Option<&'static (dyn Encoding + Send + Sync)> {
if self.sort_id == 0 {
lcid_to_encoding(self.lcid())
} else {
Expand All @@ -44,7 +44,7 @@ impl Collation {
/// 3. replace: Encoding.UNICODE with encoding::all::UTF16_LE
//
/// the unimplemented!() one's are not supported by rust-encoding
pub fn lcid_to_encoding(locale: u16) -> Option<&'static dyn Encoding> {
pub fn lcid_to_encoding(locale: u16) -> Option<&'static (dyn Encoding + Send + Sync)> {
match locale {
0x0401 => Some(encoding::all::WINDOWS_1256),
0x0402 => Some(encoding::all::WINDOWS_1251),
Expand Down Expand Up @@ -265,7 +265,7 @@ pub fn lcid_to_encoding(locale: u16) -> Option<&'static dyn Encoding> {
/// generate the code below from source code:
/// 1. (regex)replace .*\((.*?),.*?,(.*?)\) with $1 => $2
/// 2. see above/as above
pub fn sortid_to_encoding(sort_id: u8) -> Option<&'static dyn Encoding> {
pub fn sortid_to_encoding(sort_id: u8) -> Option<&'static (dyn Encoding + Send + Sync)> {
match sort_id {
// 30 | 31 | 32 | 33 | 34 | 35 => Some(encoding::all::WINDOWS_437),
// 40 | 41 | 42 | 43 | 44 | 45 | 49 => Some(encoding::all::WINDOWS_850),
Expand Down
10 changes: 4 additions & 6 deletions src/tds/stream/query.rs
@@ -1,6 +1,6 @@
use crate::tds::{codec::DoneStatus, stream::ReceivedToken};
use crate::{row::ColumnType, Column, Error, Row};
use futures::{ready, Stream, StreamExt, TryStreamExt};
use futures::{ready, stream::BoxStream, Stream, StreamExt, TryStreamExt};
use std::{
fmt::Debug,
pin::Pin,
Expand All @@ -18,7 +18,7 @@ pub(crate) enum QueryStreamState {

/// A stream of rows, needed for queries returning data.
pub struct QueryStream<'a> {
token_stream: Pin<Box<dyn Stream<Item = crate::Result<ReceivedToken>> + 'a>>,
token_stream: BoxStream<'a, crate::Result<ReceivedToken>>,
current_columns: Option<Arc<Vec<Column>>>,
previous_columns: Option<Arc<Vec<Column>>>,
pub(crate) state: QueryStreamState,
Expand All @@ -29,7 +29,7 @@ impl<'a> Debug for QueryStream<'a> {
f.debug_struct("Querystream")
.field(
"token_stream",
&"Pin<Box<dyn Stream<Item = crate::Result<ReceivedToken>> + 'a>>",
&"BoxStream<'a, crate::Result<ReceivedToken>>",
)
.field("current_columns", &self.current_columns)
.field("previous_columns", &self.previous_columns)
Expand All @@ -39,9 +39,7 @@ impl<'a> Debug for QueryStream<'a> {
}

impl<'a> QueryStream<'a> {
pub(crate) fn new(
token_stream: Pin<Box<dyn Stream<Item = crate::Result<ReceivedToken>> + 'a>>,
) -> Self {
pub(crate) fn new(token_stream: BoxStream<'a, crate::Result<ReceivedToken>>) -> Self {
Self {
token_stream,
current_columns: None,
Expand Down
9 changes: 4 additions & 5 deletions src/tds/stream/token.rs
Expand Up @@ -8,10 +8,9 @@ use crate::{
},
Error, SqlReadBytes, TokenType,
};
use futures::{Stream, TryStreamExt};
use futures::{stream::BoxStream, TryStreamExt};
use std::{
convert::TryFrom,
pin::Pin,
sync::{atomic::Ordering, Arc},
};
use tokio::io::AsyncReadExt;
Expand Down Expand Up @@ -166,8 +165,8 @@ impl<'a> TokenStream<'a> {
Ok(ReceivedToken::SSPI(sspi))
}

pub fn try_unfold(self) -> Pin<Box<dyn Stream<Item = crate::Result<ReceivedToken>> + 'a>> {
let s = futures::stream::try_unfold(self, |mut this| async move {
pub fn try_unfold(self) -> BoxStream<'a, crate::Result<ReceivedToken>> {
let stream = futures::stream::try_unfold(self, |mut this| async move {
if this.conn.is_eof() {
return Ok(None);
}
Expand Down Expand Up @@ -199,6 +198,6 @@ impl<'a> TokenStream<'a> {
Ok(Some((token, this)))
});

Box::pin(s)
Box::pin(stream)
}
}
2 changes: 1 addition & 1 deletion src/to_sql.rs
Expand Up @@ -6,7 +6,7 @@ use std::borrow::Cow;
use uuid::Uuid;

/// A conversion trait to a TDS type.
pub trait ToSql {
pub trait ToSql: Send + Sync {
/// Convert to a value understood by the SQL Server.
fn to_sql(&self) -> ColumnData<'_>;
}
Expand Down

0 comments on commit 1e65704

Please sign in to comment.