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 macro in favor of AFIT & RPITIT #211

Merged
merged 11 commits into from
Jan 31, 2024
Merged
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
toolchain: [
stable,
beta,
1.60.0 # MSRV
1.75.0 # MSRV
]
args: [
--all-features,
Expand Down
2 changes: 2 additions & 0 deletions BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

### Changed

- Remove `async_trait` macro in favor of async functions in traits (AFIT).
This bumps xtra's MSRV to `1.75`.
- `MessageChannel` is now a `struct` that can be constructed from an `Address` via `MessageChannel::new` or using `From`/`Into`.
- Move event-loop related functions from `Context` to xtra's top-level scope.
`Context` is now only used within an actor's `Handler`.
Expand Down
13 changes: 0 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ struct Printer {

struct Print(String);

#[async_trait]
impl Handler<Print> for Printer {
type Return = ();

Expand Down
1 change: 0 additions & 1 deletion macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ pub fn actor_derive(input: TokenStream) -> TokenStream {
};

quote! {
#[xtra::prelude::async_trait]
impl #impl_generics xtra::Actor for #actor_ident #type_generics #where_clause {
type Stop = ();

Expand Down
3 changes: 1 addition & 2 deletions xtra/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ documentation = "https://docs.rs/xtra"
readme = "README.md"
keywords = ["async", "actor", "futures", "xtra", "async-await"]
categories = ["asynchronous", "concurrency"]
rust-version = "1.60.0"
rust-version = "1.75.0"

[dependencies]
async-trait = "0.1.56"
catty = "0.1.5"
futures-core = "0.3.21" # alloc is the only default feature and we need it.
futures-sink = { version = "0.3.21", default-features = false, optional = true }
Expand Down
4 changes: 0 additions & 4 deletions xtra/benches/throughput.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use async_trait::async_trait;
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use tokio::runtime::Runtime;
use xtra::{Actor, Context, Handler, Mailbox};

struct Counter(u64);

#[async_trait]
impl Actor for Counter {
type Stop = ();
async fn stopped(self) {}
Expand All @@ -14,7 +12,6 @@ impl Actor for Counter {
struct IncrementZst;
struct Finish;

#[async_trait::async_trait]
impl Handler<IncrementZst> for Counter {
type Return = ();

Expand All @@ -23,7 +20,6 @@ impl Handler<IncrementZst> for Counter {
}
}

#[async_trait::async_trait]
impl Handler<Finish> for Counter {
type Return = u64;

Expand Down
2 changes: 0 additions & 2 deletions xtra/examples/address_sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ struct Add(u32);

struct GetSum;

#[async_trait]
impl Handler<Add> for Accumulator {
type Return = ();

Expand All @@ -20,7 +19,6 @@ impl Handler<Add> for Accumulator {
}
}

#[async_trait]
impl Handler<GetSum> for Accumulator {
type Return = u32;

Expand Down
1 change: 0 additions & 1 deletion xtra/examples/backpressure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ struct Greeter;

struct Hello(String);

#[async_trait]
impl Handler<Hello> for Greeter {
type Return = ();

Expand Down
1 change: 0 additions & 1 deletion xtra/examples/basic_async_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ struct Printer {

struct Print(String);

#[async_trait]
impl Handler<Print> for Printer {
type Return = ();

Expand Down
1 change: 0 additions & 1 deletion xtra/examples/basic_smol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ struct Printer {

struct Print(String);

#[async_trait]
impl Handler<Print> for Printer {
type Return = ();

Expand Down
1 change: 0 additions & 1 deletion xtra/examples/basic_tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ struct Printer {

struct Print(String);

#[async_trait]
impl Handler<Print> for Printer {
type Return = ();

Expand Down
1 change: 0 additions & 1 deletion xtra/examples/basic_wasm_bindgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ crate-type = ["cdylib", "rlib"]
wasm-bindgen = { version = "0.2.81", default-features = false }
wasm-bindgen-futures = { version = "0.4.13", default-features = false }
xtra = { path = "../..", features = ["wasm_bindgen", "macros"] }
async-trait = "0.1"

[dev-dependencies]
wasm-bindgen-test = { version = "0.3.13", default-features = false }
Expand Down
1 change: 0 additions & 1 deletion xtra/examples/basic_wasm_bindgen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ struct Echoer;

struct Echo(String);

#[async_trait]
impl Handler<Echo> for Echoer {
type Return = String;

Expand Down
5 changes: 0 additions & 5 deletions xtra/examples/crude_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ struct Increment;
struct IncrementWithData(usize);
struct GetCount;

#[async_trait]
impl Handler<Increment> for Counter {
type Return = ();

Expand All @@ -24,7 +23,6 @@ impl Handler<Increment> for Counter {
}
}

#[async_trait]
impl Handler<IncrementWithData> for Counter {
type Return = ();

Expand All @@ -33,7 +31,6 @@ impl Handler<IncrementWithData> for Counter {
}
}

#[async_trait]
impl Handler<GetCount> for Counter {
type Return = usize;

Expand All @@ -51,7 +48,6 @@ struct SendTimer {

struct GetTime;

#[async_trait]
impl Handler<GetTime> for SendTimer {
type Return = Duration;

Expand All @@ -65,7 +61,6 @@ struct ReturnTimer;

struct TimeReturn;

#[async_trait]
impl Handler<TimeReturn> for ReturnTimer {
type Return = Instant;

Expand Down
1 change: 0 additions & 1 deletion xtra/examples/custom_event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ struct Counter {

struct Inc;

#[async_trait]
impl Handler<Inc> for Counter {
type Return = ();

Expand Down
3 changes: 0 additions & 3 deletions xtra/examples/interleaved_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ struct ActorA {
actor_b: Address<ActorB>,
}

#[async_trait]
impl Handler<Hello> for ActorA {
type Return = ();

Expand All @@ -24,7 +23,6 @@ impl Handler<Hello> for ActorA {
#[derive(xtra::Actor)]
struct ActorB;

#[async_trait]
impl Handler<Initialized> for ActorB {
type Return = ();

Expand All @@ -37,7 +35,6 @@ impl Handler<Initialized> for ActorB {
}
}

#[async_trait]
impl Handler<Hello> for ActorB {
type Return = ();

Expand Down
4 changes: 1 addition & 3 deletions xtra/examples/manual_actor_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ struct MessageCounter {
}

// With a manual `Actor` implementation, we can specify a `Stop` type and thus return something from the `stopped` lifecycle callback.
#[async_trait]

impl Actor for MessageCounter {
type Stop = usize;

Expand All @@ -18,7 +18,6 @@ impl Actor for MessageCounter {
struct Ping;
struct Stop;

#[async_trait]
impl Handler<Ping> for MessageCounter {
type Return = ();

Expand All @@ -27,7 +26,6 @@ impl Handler<Ping> for MessageCounter {
}
}

#[async_trait]
impl Handler<Stop> for MessageCounter {
type Return = ();

Expand Down
1 change: 0 additions & 1 deletion xtra/examples/message_stealing_multiple_actors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ impl Printer {

struct Print(String);

#[async_trait]
impl Handler<Print> for Printer {
type Return = ();

Expand Down
1 change: 0 additions & 1 deletion xtra/examples/scoped_actor_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ struct MyActor;

struct Print(String);

#[async_trait]
impl Handler<Print> for MyActor {
type Return = ();

Expand Down
1 change: 0 additions & 1 deletion xtra/examples/send_interval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ struct Greeter;

struct Greet;

#[async_trait]
impl Handler<Greet> for Greeter {
type Return = ();

Expand Down
4 changes: 2 additions & 2 deletions xtra/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ impl<A, Rc: RefCounter> Address<A, Rc> {
/// # use xtra::prelude::*;
/// # use std::time::Duration;
/// # struct MyActor;
/// # #[async_trait] impl Actor for MyActor {type Stop = (); async fn stopped(self) -> Self::Stop {} }
/// # impl Actor for MyActor {type Stop = (); async fn stopped(self) -> Self::Stop {} }
/// struct Shutdown;
///
/// #[async_trait]
///
/// impl Handler<Shutdown> for MyActor {
/// type Return = ();
///
Expand Down
1 change: 0 additions & 1 deletion xtra/src/chan/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,6 @@ mod tests {

struct Foo;

#[async_trait::async_trait]
impl crate::Actor for Foo {
type Stop = ();

Expand Down
3 changes: 2 additions & 1 deletion xtra/src/dispatch_future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ impl<'a, A> DispatchFuture<'a, A> {
/// In case this future has not yet been polled, a new span will be created which is why this function takes `&mut self`.
///
/// ```rust

/// # use std::ops::ControlFlow;
/// # use std::time::Duration;
/// # use tokio::time::timeout;
/// # use xtra::prelude::*;
/// #
/// # struct MyActor;
/// # #[async_trait::async_trait] impl Actor for MyActor { type Stop = (); async fn stopped(self) {} }
/// # impl Actor for MyActor { type Stop = (); async fn stopped(self) {} }
/// #
/// # let mut actor = MyActor;
/// # let (addr, mut mailbox) = Mailbox::unbounded();
Expand Down
Loading
Loading