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

Remove #[async_trait] attribute #324

Merged
merged 7 commits into from
Mar 22, 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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ jobs:
strategy:
fail-fast: false
matrix:
msrv: ["1.70.0"]
msrv: ["1.75.0"]
crate:
- cucumber-codegen
- cucumber
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ All user visible changes to `cucumber` crate will be documented in this file. Th



## [0.21.0] · 2024-??-?? (unreleased)
[0.21.0]: /../../tree/v0.21.0

[Diff](/../../compare/v0.20.2...v0.21.0) | [Milestone](/../../milestone/26)

### BC Breaks

- Removed `#[async_trait]` attribute from `World`, `Writer` and `writer::Arbitrary` traits. ([#324])
- Bumped up [MSRV] to 1.75 for using `async fn` in traits. ([#324])

[#324]: /../../pull/324




## [0.20.2] · 2023-12-04
[0.20.2]: /../../tree/v0.20.2

Expand Down
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "cucumber"
version = "0.20.2"
edition = "2021"
rust-version = "1.70"
rust-version = "1.75"
description = """\
Cucumber testing framework for Rust, with async support. \
Fully native, no external test runners or dependencies.\
Expand Down Expand Up @@ -63,7 +63,6 @@ timestamps = []
tracing = ["dep:crossbeam-utils", "dep:tracing", "dep:tracing-subscriber"]

[dependencies]
async-trait = "0.1.43"
clap = { version = "4.3.2", features = ["derive", "wrap_help"] }
console = "0.15"
derive_more = { version = "0.99.17", features = ["as_ref", "deref", "deref_mut", "display", "error", "from", "from_str", "into"], default_features = false }
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Cucumber testing framework for Rust
===================================

[![crates.io](https://img.shields.io/crates/v/cucumber.svg?maxAge=2592000 "crates.io")](https://crates.io/crates/cucumber)
[![Rust 1.70+](https://img.shields.io/badge/rustc-1.70+-lightgray.svg "Rust 1.70+")](https://blog.rust-lang.org/2023/06/01/Rust-1.70.0.html)
[![Rust 1.75+](https://img.shields.io/badge/rustc-1.75+-lightgray.svg "Rust 1.75")](https://blog.rust-lang.org/2023/12/28/Rust-1.75.0.html)
[![Unsafe Forbidden](https://img.shields.io/badge/unsafe-forbidden-success.svg "Unsafe forbidden")](https://github.com/rust-secure-code/safety-dance)
[![CI](https://github.com/cucumber-rs/cucumber/workflows/CI/badge.svg?branch=main "CI")](https://github.com/cucumber-rs/cucumber/actions?query=workflow%3ACI+branch%3Amain)
[![Rust docs](https://docs.rs/cucumber/badge.svg "Rust docs")](https://docs.rs/cucumber)
Expand Down
6 changes: 0 additions & 6 deletions book/src/architecture/writer.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ Finally, let's implement a custom [`Writer`] which simply outputs [cucumber even
[`Writer`] represents anything that consumes a [`Stream`] of [cucumber events][`event::Cucumber`].

```rust
# extern crate async_trait;
# extern crate cucumber;
# extern crate futures;
# extern crate once_cell;
Expand All @@ -19,7 +18,6 @@ Finally, let's implement a custom [`Writer`] which simply outputs [cucumber even
# time::Duration,
# };
#
# use async_trait::async_trait;
# use cucumber::{
# cli, event, gherkin, given, parser, step, then, when, Event, World,
# WriterExt as _,
Expand Down Expand Up @@ -244,7 +242,6 @@ Finally, let's implement a custom [`Writer`] which simply outputs [cucumber even
#
struct CustomWriter;

#[async_trait(?Send)]
impl<W: 'static> cucumber::Writer<W> for CustomWriter {
type Cli = cli::Empty; // we provide no CLI options

Expand Down Expand Up @@ -299,14 +296,12 @@ async fn main() {
> __TIP__: `CustomWriter` will print trash if we feed unordered [`event::Cucumber`]s into it. Though, we shouldn't care about order normalization in our implementations. Instead, we may just wrap `CustomWriter` into [`writer::Normalize`], which will do that for us.

```rust
# extern crate async_trait;
# extern crate cucumber;
# extern crate futures;
# extern crate tokio;
#
# use std::{path::PathBuf, time::Duration};
#
# use async_trait::async_trait;
# use cucumber::{
# cli, event, gherkin, given, parser, then, when, Event, World,
# WriterExt as _,
Expand Down Expand Up @@ -418,7 +413,6 @@ async fn main() {
#
# struct CustomWriter;
#
# #[async_trait(?Send)]
# impl<W: 'static> cucumber::Writer<W> for CustomWriter {
# type Cli = cli::Empty; // we provide no CLI options
#
Expand Down
14 changes: 14 additions & 0 deletions codegen/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ All user visible changes to `cucumber-codegen` crate will be documented in this



## [0.21.0] · 2024-??-?? (unreleased)
[0.21.0]: /../../tree/v0.20.0/codegen

[Milestone](/../../milestone/26)

### BC Breaks

- Bumped up [MSRV] to 1.75 for using `async fn` in traits. ([#324])

[#324]: /../../pull/324




## [0.20.2] · 2023-12-04
[0.20.2]: /../../tree/v0.20.2/codegen

Expand Down
3 changes: 1 addition & 2 deletions codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "cucumber-codegen"
version = "0.20.2" # should be the same as main crate version
edition = "2021"
rust-version = "1.70"
rust-version = "1.75"
description = "Code generation for `cucumber` crate."
license = "MIT OR Apache-2.0"
authors = [
Expand Down Expand Up @@ -31,7 +31,6 @@ syn = { version = "2.0", features = ["derive", "extra-traits", "full"] }
synthez = "0.3"

[dev-dependencies]
async-trait = "0.1"
cucumber = { path = "..", features = ["libtest", "macros"] }
derive_more = "0.99.17"
futures = "0.3.17"
Expand Down
2 changes: 1 addition & 1 deletion codegen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
========================

[![crates.io](https://img.shields.io/crates/v/cucumber-codegen.svg?maxAge=2592000 "crates.io")](https://crates.io/crates/cucumber-codegen)
[![Rust 1.70+](https://img.shields.io/badge/rustc-1.70+-lightgray.svg "Rust 1.70+")](https://blog.rust-lang.org/2023/06/01/Rust-1.70.0.html)
[![Rust 1.75+](https://img.shields.io/badge/rustc-1.75+-lightgray.svg "Rust 1.75")](https://blog.rust-lang.org/2023/12/28/Rust-1.75.0.html)
[![Unsafe Forbidden](https://img.shields.io/badge/unsafe-forbidden-success.svg "Unsafe forbidden")](https://github.com/rust-secure-code/safety-dance)
[![CI](https://github.com/cucumber-rs/cucumber/workflows/CI/badge.svg?branch=main "CI")](https://github.com/cucumber-rs/cucumber/actions?query=workflow%3ACI+branch%3Amain)
[![Rust docs](https://docs.rs/cucumber-codegen/badge.svg "Rust docs")](https://docs.rs/cucumber-codegen)
Expand Down
11 changes: 0 additions & 11 deletions codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,6 @@ mod world;

use proc_macro::TokenStream;

// TODO: Remove once tests run without complains about it.
#[cfg(test)]
mod actually_used_crates_in_tests {
use async_trait as _;
use cucumber as _;
use derive_more as _;
use futures as _;
use tempfile as _;
use tokio as _;
}

/// Helper macro for generating public shims for [`macro@given`], [`macro@when`]
/// and [`macro@then`] attributes.
macro_rules! step_attribute {
Expand Down
4 changes: 0 additions & 4 deletions codegen/src/world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ impl Definition {

quote! {
#[automatically_derived]
#[::cucumber::codegen::async_trait(?Send)]
impl #impl_gens ::cucumber::World for #world #ty_gens
#where_clause
{
Expand Down Expand Up @@ -219,7 +218,6 @@ mod spec {
}

#[automatically_derived]
#[::cucumber::codegen::async_trait(?Send)]
impl ::cucumber::World for World {
type Error = ::cucumber::codegen::anyhow::Error;

Expand Down Expand Up @@ -349,7 +347,6 @@ mod spec {
}

#[automatically_derived]
#[::cucumber::codegen::async_trait(?Send)]
impl<T> ::cucumber::World for World<T> {
type Error = ::cucumber::codegen::anyhow::Error;

Expand Down Expand Up @@ -480,7 +477,6 @@ mod spec {
}

#[automatically_derived]
#[::cucumber::codegen::async_trait(?Send)]
impl<T> ::cucumber::World for World<T> {
type Error = ::cucumber::codegen::anyhow::Error;

Expand Down
13 changes: 3 additions & 10 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ impl Colored for Empty {}
/// This struct is especially useful, when implementing custom [`Writer`]
/// wrapping another one:
/// ```rust
/// # use async_trait::async_trait;
/// # use cucumber::{cli, event, parser, writer, Event, World, Writer};
/// #
/// struct CustomWriter<Wr>(Wr);
Expand All @@ -193,7 +192,6 @@ impl Colored for Empty {}
/// custom_option: Option<String>,
/// }
///
/// #[async_trait(?Send)]
/// impl<W, Wr> Writer<W> for CustomWriter<Wr>
/// where
/// W: World,
Expand All @@ -216,17 +214,12 @@ impl Colored for Empty {}
///
/// impl cli::Colored for Cli {}
///
/// #[async_trait(?Send)]
/// impl<'val, W, Wr, Val> writer::Arbitrary<'val, W, Val> for CustomWriter<Wr>
/// impl<W, Wr, Val> writer::Arbitrary<W, Val> for CustomWriter<Wr>
/// where
/// Wr: writer::Arbitrary<'val, W, Val>,
/// Val: 'val,
/// Wr: writer::Arbitrary<W, Val>,
/// Self: Writer<W>,
/// {
/// async fn write(&mut self, val: Val)
/// where
/// 'val: 'async_trait,
/// {
/// async fn write(&mut self, val: Val) {
/// self.0.write(val).await;
/// }
/// }
Expand Down
7 changes: 0 additions & 7 deletions src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use futures::future;
use crate::{step, Step, World};

pub use anyhow;
pub use async_trait::async_trait;
pub use cucumber_expressions::{
expand::parameters::Provider as ParametersProvider, Expression, Spanned,
};
Expand Down Expand Up @@ -112,12 +111,9 @@ pub const fn str_eq(l: &str, r: &str) -> bool {
/// argument, by automatically wrapping sync functions in a [`future::Ready`].
///
/// ```rust
/// # use async_trait::async_trait;
/// #
/// # #[derive(Default)]
/// # struct World;
/// #
/// #[async_trait(?Send)]
/// impl cucumber::World for World {
/// type Error = anyhow::Error;
///
Expand Down Expand Up @@ -180,12 +176,9 @@ where
/// functions in a [`Result`]`<`[`World`]`, `[`Infallible`]`>`.
///
/// ```rust
/// # use async_trait::async_trait;
/// #
/// # #[derive(Default)]
/// # struct World;
/// #
/// #[async_trait(?Send)]
/// impl cucumber::World for World {
/// type Error = anyhow::Error;
///
Expand Down
15 changes: 6 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,9 @@ mod actually_used_crates_in_tests_and_book {
use tokio as _;
}

use std::fmt::Display;
#[cfg(feature = "macros")]
use std::{fmt::Debug, path::Path};

use async_trait::async_trait;
use std::{fmt::Display, future::Future};

#[cfg(feature = "macros")]
use self::{
Expand Down Expand Up @@ -229,13 +227,12 @@ pub use self::{
/// [1]: https://docs.rs/once_cell
/// [2]: https://doc.rust-lang.org/book/ch16-03-shared-state.html
/// [Cucumber]: https://cucumber.io
#[async_trait(?Send)]
pub trait World: Sized + 'static {
/// Error of creating a new [`World`] instance.
type Error: Display;

/// Creates a new [`World`] instance.
async fn new() -> Result<Self, Self::Error>;
fn new() -> impl Future<Output = Result<Self, Self::Error>>;

#[cfg(feature = "macros")]
/// Returns runner for tests with auto-wired steps marked by [`given`],
Expand Down Expand Up @@ -287,11 +284,11 @@ pub trait World: Sized + 'static {
/// [`Step`] panicked.
///
/// [`Feature`]: gherkin::Feature
async fn run<I: AsRef<Path>>(input: I)
fn run<I: AsRef<Path>>(input: I) -> impl Future<Output = ()>
where
Self: Debug + WorldInventory,
{
Self::cucumber().run_and_exit(input).await;
Self::cucumber().run_and_exit(input)
}

#[cfg(feature = "macros")]
Expand All @@ -308,7 +305,7 @@ pub trait World: Sized + 'static {
/// [`Feature`]: gherkin::Feature
/// [`Scenario`]: gherkin::Scenario
/// [`Step`]: gherkin::Step
async fn filter_run<I, F>(input: I, filter: F)
fn filter_run<I, F>(input: I, filter: F) -> impl Future<Output = ()>
where
Self: Debug + WorldInventory,
I: AsRef<Path>,
Expand All @@ -319,6 +316,6 @@ pub trait World: Sized + 'static {
) -> bool
+ 'static,
{
Self::cucumber().filter_run_and_exit(input, filter).await;
Self::cucumber().filter_run_and_exit(input, filter)
}
}
16 changes: 5 additions & 11 deletions src/writer/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use std::{
str::FromStr,
};

use async_trait::async_trait;
use derive_more::{Deref, DerefMut};
use itertools::Itertools as _;
use once_cell::sync::Lazy;
Expand Down Expand Up @@ -132,7 +131,6 @@ pub struct Basic<Out: io::Write = io::Stdout> {
verbosity: Verbosity,
}

#[async_trait(?Send)]
impl<W, Out> Writer<W> for Basic<Out>
where
W: World + Debug,
Expand Down Expand Up @@ -163,23 +161,19 @@ where
Feature::Finished => Ok(()),
},
}
.unwrap_or_else(|e| panic!("Failed to write into terminal: {e}"));
.unwrap_or_else(|e| panic!("failed to write into terminal: {e}"));
}
}

#[async_trait(?Send)]
impl<'val, W, Val, Out> writer::Arbitrary<'val, W, Val> for Basic<Out>
impl<W, Val, Out> writer::Arbitrary<W, Val> for Basic<Out>
where
W: World + Debug,
Val: AsRef<str> + 'val,
Val: AsRef<str>,
Out: io::Write,
{
async fn write(&mut self, val: Val)
where
'val: 'async_trait,
{
async fn write(&mut self, val: Val) {
self.write_line(val.as_ref())
.unwrap_or_else(|e| panic!("Failed to write: {e}"));
.unwrap_or_else(|e| panic!("failed to write: {e}"));
}
}

Expand Down
Loading
Loading