Skip to content

Fix IntoFuture bug #944

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

Merged
merged 4 commits into from
Jul 19, 2022
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
13 changes: 13 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@ jobs:
echo "Run ./eng/scripts/cargo_readme.sh to update readmes" && exit 1
fi

nightly:
name: Test Nightly
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
profile: minimal
override: true
- name: check `into_future` feature
run: cargo check --all --features into_future

test-services:
name: Services Tests
runs-on: ubuntu-20.04
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
url = "2.2"
uuid = { version = "1.0" }
pin-project = "1.0.10"
pin-project = "1.0"
paste = "1.0"

# Add dependency to getrandom to enable WASM support
Expand Down
12 changes: 6 additions & 6 deletions sdk/core/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ macro_rules! operation {
// Construct the builder.
(@builder
// The name of the operation and any generic params along with their constraints
$name:ident<$($generic:ident: $first_constraint:ident $(+ $constraint:ident)* ),*>,
$name:ident<$($generic:ident: $first_constraint:ident $(+ $constraint:ident)* ),* $(+ $lt:lifetime)?>,
// The client
client: $client:ty,
// The required fields that will be used in the constructor
Expand Down Expand Up @@ -170,7 +170,7 @@ macro_rules! operation {
}
};
// Construct a builder and the `Future` related code
($name:ident<$($generic:ident: $first_constraint:ident $(+ $constraint:ident)* ),*>,
($name:ident<$($generic:ident: $first_constraint:ident $(+ $constraint:ident)* ),* $(+ $lt:lifetime)?>,
client: $client:ty,
@required
$($required:ident: $rtype:ty,)*
Expand All @@ -180,7 +180,7 @@ macro_rules! operation {
$($nosetter:ident: $nstype:ty),*
) => {
$crate::operation! {
@builder $name<$($generic: $first_constraint $(+ $constraint)*),*>,
@builder $name<$($generic: $first_constraint $(+ $constraint)*),* $(+ $lt)*>,
client: $client,
@required
$($required: $rtype,)*
Expand All @@ -192,7 +192,7 @@ macro_rules! operation {
$crate::future!($name);
azure_core::__private::paste! {
#[cfg(feature = "into_future")]
impl std::future::IntoFuture for [<$name Builder>] {
impl <$($generic: $first_constraint $(+ $constraint)*)* $(+ $lt)*> std::future::IntoFuture for [<$name Builder>]<$($generic),*> {
type IntoFuture = $name;
type Output = <$name as std::future::Future>::Output;
fn into_future(self) -> Self::IntoFuture {
Expand Down Expand Up @@ -251,13 +251,13 @@ macro_rules! operation {
}
};
// `operation! { CreateDocument<D: Serialize>, client: UserClient, ?consistency_level: ConsistencyLevel, ??other_field: bool }`
($name:ident<$($generic:ident: $first_constraint:ident $(+ $constraint:ident)*),*>,
($name:ident<$($generic:ident: $first_constraint:ident $(+ $constraint:ident)*),* $(+ $lt:lifetime)?>,
client: $client:ty,
$($required:ident: $rtype:ty,)*
$(?$optional:ident: $otype:ty,)*
$(#[skip] $nosetter:ident: $nstype:ty),*) => {
$crate::operation!{
$name<$($generic: $first_constraint $(+ $constraint)*),*>,
$name<$($generic: $first_constraint $(+ $constraint)*),* $(+ $lt)*>,
client: $client,
@required
$($required: $rtype,)*
Expand Down
27 changes: 18 additions & 9 deletions sdk/core/src/pageable.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use futures::stream::unfold;
use futures::Stream;
use pin_project::pin_project;

/// Helper macro for unwrapping `Result`s into the right types
/// that `futures::stream::unfold` expects.
Expand All @@ -19,15 +18,25 @@ macro_rules! r#try {
/// for conditionally compiling with a `Send` constraint or not.
macro_rules! declare {
($($extra:tt)*) => {
/// A pageable stream that yields items of type `T`
///
/// Internally uses the Azure specific continuation header to
/// make repeated requests to Azure yielding a new page each time.
#[pin_project]
pub struct Pageable<T, E> {
#[pin]
stream: std::pin::Pin<Box<dyn Stream<Item = Result<T, E>> $($extra)*>>,
// The use of a module here is a hack to get around the fact that `pin_project`
// generates a method `project_ref` which is never used and generates a warning.
// The module allows us to declare that `dead_code` is allowed but only for
// the `Pageable` type.
mod pageable {
#![allow(dead_code)]
use super::*;
/// A pageable stream that yields items of type `T`
///
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, remove

/// Internally uses the Azure specific continuation header to
/// make repeated requests to Azure yielding a new page each time.
#[pin_project::pin_project]
// This is to surpress the unused `project_ref` warning
pub struct Pageable<T, E> {
#[pin]
pub(crate) stream: std::pin::Pin<Box<dyn Stream<Item = Result<T, E>> $($extra)*>>,
}
}
pub use pageable::Pageable;

impl<T, E> Pageable<T, E>
where
Expand Down
1 change: 0 additions & 1 deletion sdk/data_cosmos/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#![allow(clippy::enum_variant_names)]
#![allow(clippy::new_without_default)]
#![allow(clippy::module_inception)]
#![cfg_attr(feature = "into_future", feature(into_future))]

/*!
# The Cosmos DB crate.
Expand Down
2 changes: 1 addition & 1 deletion sdk/data_cosmos/src/operations/create_document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::convert::TryFrom;
use azure_core::{collect_pinned_stream, Response as HttpResponse};

operation! {
CreateDocument<D: Serialize + CosmosEntity + Send>,
CreateDocument<D: Serialize + CosmosEntity + Send + 'static>,
client: CollectionClient,
document: D,
?is_upsert: bool,
Expand Down
2 changes: 1 addition & 1 deletion sdk/data_cosmos/src/operations/replace_document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use chrono::{DateTime, Utc};
use serde::Serialize;

operation! {
ReplaceDocument<D: Serialize + Send>,
ReplaceDocument<D: Serialize + Send + 'static>,
client: DocumentClient,
document: D,
?indexing_directive: IndexingDirective,
Expand Down
2 changes: 0 additions & 2 deletions sdk/data_tables/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![cfg_attr(feature = "into_future", feature(into_future))]

#[macro_use]
extern crate log;
#[macro_use]
Expand Down
2 changes: 0 additions & 2 deletions sdk/storage_blobs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![cfg_attr(feature = "into_future", feature(into_future))]

#[macro_use]
extern crate serde_derive;
#[macro_use]
Expand Down