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 the need for the async_trait crate by leveraging the native async fns support now in Rust as of v1.75 #202

Merged
merged 1 commit into from
Feb 18, 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
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ractor

<p align="center">
<img src="https://raw.githubusercontent.com/slawlor/ractor/main/docs/ractor_logo.svg" width="50%" />
<img src="https://raw.githubusercontent.com/slawlor/ractor/main/docs/ractor_logo.svg" width="50%" />
</p>

*Pronounced ract-er*
Expand Down Expand Up @@ -64,7 +64,7 @@ Install `ractor` by adding the following to your Cargo.toml dependencies.
ractor = "0.9"
```

The minimum supported Rust version (MSRV) of `ractor` is `1.64`
The minimum supported Rust version (MSRV) of `ractor` is `1.64`. However to utilize the native `async fn` support in traits and not rely on the `async-trait` crate's desugaring functionliaty, you need to be on Rust version `>= 1.75`. The stabilization of `async fn` in traits [was recently added](https://blog.rust-lang.org/2023/12/21/async-fn-rpit-in-traits.html).

## Features

Expand All @@ -81,7 +81,7 @@ never be executed in parallel. Following the actor model leads to microservices
An example `ping-pong` actor might be the following

```rust
use ractor::{async_trait, cast, Actor, ActorProcessingErr, ActorRef};
use ractor::{cast, Actor, ActorProcessingErr, ActorRef};

/// [PingPong] is a basic actor that will print
/// ping..pong.. repeatedly until some exit
Expand Down Expand Up @@ -114,7 +114,6 @@ impl Message {
}

// the implementation of our actor's "logic"
#[async_trait]
impl Actor for PingPong {
// An actor has a message type
type Msg = Message;
Expand Down
7 changes: 4 additions & 3 deletions ractor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@ cluster = []
tokio_runtime = ["tokio/time", "tokio/rt", "tokio/macros", "tokio/tracing"]

# default = ["async-std"]
default = ["tokio_runtime"]
default = ["tokio_runtime", "async-trait"]

[dependencies]
## Required dependencies
async-trait = "0.1"
dashmap = "5"
futures = "0.3"
once_cell = "1"
rand = "0.8"

## Configurable dependencies
# Tracing feature requires --cfg=tokio_unstable
tokio = { version = "1", features = ["sync"] }
async-std = { version = "1", features = ["attributes"], optional = true }
async-trait = { version = "0.1", optional = true }
tokio = { version = "1", features = ["sync"] }
tracing = { version = "0.1", features = ["attributes"] }

[dev-dependencies]
Expand Down
4 changes: 2 additions & 2 deletions ractor/benches/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct BenchActorMessage;
#[cfg(feature = "cluster")]
impl Message for BenchActorMessage {}

#[async_trait::async_trait]
#[cfg_attr(feature = "async-trait", ractor::async_trait)]
impl Actor for BenchActor {
type Msg = BenchActorMessage;

Expand Down Expand Up @@ -247,7 +247,7 @@ fn process_messages(c: &mut Criterion) {
num_msgs: u64,
}

#[async_trait::async_trait]
#[cfg_attr(feature = "async-trait", ractor::async_trait)]
impl Actor for MessagingActor {
type Msg = BenchActorMessage;

Expand Down
4 changes: 2 additions & 2 deletions ractor/examples/counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
extern crate ractor;

use ractor::{async_trait, call_t, Actor, ActorProcessingErr, ActorRef, RpcReplyPort};
use ractor::{call_t, Actor, ActorProcessingErr, ActorRef, RpcReplyPort};

struct Counter;

Expand All @@ -31,7 +31,7 @@ enum CounterMessage {
#[cfg(feature = "cluster")]
impl ractor::Message for CounterMessage {}

#[async_trait]
#[cfg_attr(feature = "async-trait", ractor::async_trait)]
impl Actor for Counter {
type Msg = CounterMessage;

Expand Down
6 changes: 3 additions & 3 deletions ractor/examples/monte_carlo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use std::collections::HashMap;

use ractor::{async_trait, cast, Actor, ActorId, ActorProcessingErr, ActorRef};
use ractor::{cast, Actor, ActorId, ActorProcessingErr, ActorRef};
use rand::{thread_rng, Rng};

// ================== Player Actor ================== //
Expand Down Expand Up @@ -62,7 +62,7 @@ struct GameMessage(ActorRef<GameManagerMessage>);
#[cfg(feature = "cluster")]
impl ractor::Message for GameMessage {}

#[async_trait]
#[cfg_attr(feature = "async-trait", ractor::async_trait)]
impl Actor for Game {
type Msg = GameMessage;

Expand Down Expand Up @@ -139,7 +139,7 @@ impl GameManagerState {
}
}

#[async_trait]
#[cfg_attr(feature = "async-trait", ractor::async_trait)]
impl Actor for GameManager {
type Msg = GameManagerMessage;

Expand Down
6 changes: 3 additions & 3 deletions ractor/examples/output_port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extern crate ractor;

use std::sync::Arc;

use ractor::{async_trait, Actor, ActorProcessingErr, ActorRef, OutputPort};
use ractor::{Actor, ActorProcessingErr, ActorRef, OutputPort};
use tokio::time::{timeout, Duration};

enum PublisherMessage {
Expand All @@ -31,7 +31,7 @@ impl ractor::Message for Output {}

struct Publisher;

#[async_trait]
#[cfg_attr(feature = "async-trait", ractor::async_trait)]
impl Actor for Publisher {
type Msg = PublisherMessage;

Expand Down Expand Up @@ -70,7 +70,7 @@ enum SubscriberMessage {
#[cfg(feature = "cluster")]
impl ractor::Message for SubscriberMessage {}

#[async_trait]
#[cfg_attr(feature = "async-trait", ractor::async_trait)]
impl Actor for Subscriber {
type Msg = SubscriberMessage;

Expand Down
8 changes: 3 additions & 5 deletions ractor/examples/philosophers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
use std::collections::{HashMap, VecDeque};

use ractor::{
async_trait, cast, Actor, ActorId, ActorName, ActorProcessingErr, ActorRef, RpcReplyPort,
};
use ractor::{cast, Actor, ActorId, ActorName, ActorProcessingErr, ActorRef, RpcReplyPort};
use tokio::time::{Duration, Instant};

// ============================ Fork Actor ============================ //
Expand Down Expand Up @@ -113,7 +111,7 @@ impl Fork {
}
}

#[async_trait]
#[cfg_attr(feature = "async-trait", ractor::async_trait)]
impl Actor for Fork {
type Msg = ForkMessage;
type State = ForkState;
Expand Down Expand Up @@ -326,7 +324,7 @@ impl Philosopher {
}
}

#[async_trait]
#[cfg_attr(feature = "async-trait", ractor::async_trait)]
impl Actor for Philosopher {
type Msg = PhilosopherMessage;
type State = PhilosopherState;
Expand Down
4 changes: 2 additions & 2 deletions ractor/examples/ping_pong.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
extern crate ractor;

use ractor::{async_trait, cast, Actor, ActorProcessingErr, ActorRef};
use ractor::{cast, Actor, ActorProcessingErr, ActorRef};

pub struct PingPong;

Expand Down Expand Up @@ -42,7 +42,7 @@ impl Message {
}
}

#[async_trait]
#[cfg_attr(feature = "async-trait", ractor::async_trait)]
impl Actor for PingPong {
type Msg = Message;

Expand Down
8 changes: 4 additions & 4 deletions ractor/examples/supervisor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//! cargo run --example supervisor
//! ```
use ractor::{async_trait, Actor, ActorProcessingErr, ActorRef, RpcReplyPort, SupervisionEvent};
use ractor::{Actor, ActorProcessingErr, ActorRef, RpcReplyPort, SupervisionEvent};

use tokio::time::Duration;

Expand Down Expand Up @@ -97,7 +97,7 @@ enum LeafActorMessage {
#[cfg(feature = "cluster")]
impl ractor::Message for LeafActorMessage {}

#[async_trait]
#[cfg_attr(feature = "async-trait", ractor::async_trait)]
impl Actor for LeafActor {
type Msg = LeafActorMessage;
type State = LeafActorState;
Expand Down Expand Up @@ -160,7 +160,7 @@ enum MidLevelActorMessage {
#[cfg(feature = "cluster")]
impl ractor::Message for MidLevelActorMessage {}

#[async_trait]
#[cfg_attr(feature = "async-trait", ractor::async_trait)]
impl Actor for MidLevelActor {
type Msg = MidLevelActorMessage;
type State = MidLevelActorState;
Expand Down Expand Up @@ -240,7 +240,7 @@ enum RootActorMessage {
#[cfg(feature = "cluster")]
impl ractor::Message for RootActorMessage {}

#[async_trait]
#[cfg_attr(feature = "async-trait", ractor::async_trait)]
impl Actor for RootActor {
type Msg = RootActorMessage;
type State = RootActorState;
Expand Down
Loading
Loading