Skip to content
This repository has been archived by the owner on Dec 25, 2022. It is now read-only.

[WIP] Migrate to newest Actix #63

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ guide/build/

# Folder generated by mdbook when following the README.md instructions.
/actix/book

# intellij files
**/.idea
Comment on lines +19 to +20
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer to place it on your gitignore config.

7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ categories = ["network-programming", "asynchronous",
"web-programming::websocket"]
license = "MIT OR Apache-2.0"
exclude = [".gitignore", "/.github", ".cargo/config"]
edition = "2018"
edition = "2021"

[dependencies]
actix = "0.10.0"
actix-rt = "1.1"

actix = "0.13"
actix-rt = "2.7"
doc-comment = "0.3"
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
This repository is an [`mdBook`](https://github.com/rust-lang/mdBook)
project. To use it for this project:

- Install `mdBook` if you haven't already: `cargo install mdbook`
- In the `actix` directory: `mdbook watch -o`
- Install `mdBook`: `cargo install mdbook`
- Install `linkcheck`: `cargo install mdbook-linkcheck`
- Run from repo root: `mdbook watch -o actix`
- This automatically opens your browser and watches the md files for changing
- You'll still have to refresh the page, as there is no hot-reloading for
`mdbook`
- You'll still have to refresh the page, as there is no hot-reloading for `mdbook`
4 changes: 2 additions & 2 deletions actix/src/sec-0-quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ If you already have rustup installed, run this command to ensure you have the la
rustup update
```

The actix framework requires Rust version 1.40.0 and up.
The actix framework requires Rust version 1.54.0 and up.

## Running Examples

Expand All @@ -31,4 +31,4 @@ cd actix
cargo run --example ping
```

Check [examples/](https://github.com/actix/actix/tree/master/actix/examples) directory for more examples.
Check [examples/](https://github.com/actix/actix/tree/HEAD/actix/examples) directory for more examples, or see many more [community examples](https://github.com/actix/examples).
9 changes: 2 additions & 7 deletions actix/src/sec-1-getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@ contains the following:

```toml
[dependencies]
actix = "0.11.0"
actix-rt = "2.2" # <-- Runtime for actix
actix = "0.13"
actix-rt = "2.7" # <-- Runtime for actix
```

Let's create an actor that will accept a `Ping` message and respond with the number of pings processed.

An actor is a type that implements the `Actor` trait:

```rust
# extern crate actix;
use actix::prelude::*;

struct MyActor {
Expand All @@ -50,7 +49,6 @@ Now we need to define the `Message` that the actor needs to accept. The message
that implements the `Message` trait.

```rust
# extern crate actix;
use actix::prelude::*;

#[derive(Message)]
Expand All @@ -68,7 +66,6 @@ And finally, we need to declare that our actor `MyActor` can accept `Ping` and h
To do this, the actor needs to implement the `Handler<Ping>` trait.

```rust
# extern crate actix;
# use actix::prelude::*;
#
# struct MyActor {
Expand Down Expand Up @@ -114,8 +111,6 @@ Here we use the actix-rt as way to start our System and drive our main Future
so we can easily `.await` for the messages sent to the Actor.

```rust
# extern crate actix;
# extern crate actix_rt;
# use actix::prelude::*;
# struct MyActor {
# count: usize,
Expand Down
7 changes: 1 addition & 6 deletions actix/src/sec-2-actor.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ Let's define a simple `Ping` message - an actor which will accept this message n
`Result<bool, std::io::Error>`.

```rust
# extern crate actix;
use actix::prelude::*;

struct Ping;
Expand All @@ -99,8 +98,6 @@ creating actors; for details check the docs.
## Complete example

```rust
# extern crate actix;
# extern crate actix_rt;
use actix::prelude::*;

/// Define message
Expand Down Expand Up @@ -170,8 +167,6 @@ Here's an example where we're responding to a `Ping` message with a `GotPing`,
and responding with `GotPong` for a `Pong` message.

```rust
# extern crate actix;
# extern crate actix_rt;
use actix::dev::{MessageResponse,OneshotSender};
use actix::prelude::*;

Expand All @@ -192,7 +187,7 @@ where
A: Actor,
M: Message<Result = Responses>,
{
fn handle(self, ctx: &mut A::Context, tx: Option<OneshotSender<M::Result>>) {
fn handle(self, _ctx: &mut A::Context, tx: Option<OneshotSender<M::Result>>) {
if let Some(tx) = tx {
tx.send(self);
}
Expand Down
14 changes: 7 additions & 7 deletions actix/src/sec-3-address.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ Here is an example of `Actor::start()` method usage. In this example `MyActor` a
is asynchronous and is started in the same thread as the caller - threads are covered in
the [SyncArbiter] chapter.

```rust
# extern crate actix;
```rust, should_panic
// FIXME: THIS EXAMPLE IS BROKEN, AND NEEDS TO BE FIXED

# use actix::prelude::*;
#
struct MyActor;
Expand All @@ -20,7 +21,7 @@ impl Actor for MyActor {
}

# fn main() {
# System::new("test");
# System::new();
let addr = MyActor.start();
# }
```
Expand All @@ -29,7 +30,6 @@ An async actor can get its address from the `Context` struct. The context needs
implement the `AsyncContext` trait. `AsyncContext::address()` provides the actor's address.

```rust
# extern crate actix;
# use actix::prelude::*;
#
struct MyActor;
Expand Down Expand Up @@ -88,8 +88,8 @@ For example recipient can be used for a subscription system. In the following ex
`OrderEvents` actor sends a `OrderShipped` message to all subscribers. A subscriber can
be any actor that implements the `Handler<OrderShipped>` trait.

```rust
# extern crate actix;
```rust, should_panic
// FIXME: THIS EXAMPLE IS BROKEN, AND NEEDS TO BE FIXED
use actix::prelude::*;

#[derive(Message)]
Expand Down Expand Up @@ -177,7 +177,7 @@ impl Handler<OrderShipped> for SmsSubscriber {
}

fn main() {
let system = System::new("events");
let system = System::new();
let email_subscriber = Subscribe(EmailSubscriber{}.start().recipient());
let sms_subscriber = Subscribe(SmsSubscriber{}.start().recipient());
let order_event = OrderEvents::new().start();
Expand Down
14 changes: 6 additions & 8 deletions actix/src/sec-4-context.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ calls specific message handlers. Mailboxes in general are bounded. The capacity
specific to the context implementation. For the `Context` type the capacity is set to
16 messages by default and can be increased with [`Context::set_mailbox_capacity()`].

```rust
# extern crate actix;
```rust, should_panic
// FIXME: THIS EXAMPLE IS BROKEN, AND NEEDS TO BE FIXED
# use actix::prelude::*;
#
struct MyActor;
Expand All @@ -26,7 +26,7 @@ impl Actor for MyActor {
}

# fn main() {
# System::new("test");
# System::new();
let addr = MyActor.start();
# }
```
Expand All @@ -46,8 +46,8 @@ to a message. If you want an actor to send a message to itself, have a look at

To get your address from the context you call [`Context::address()`]. An example is:

```rust
# extern crate actix;
```rust, should_panic
// FIXME: THIS EXAMPLE IS BROKEN, AND NEEDS TO BE FIXED
# use actix::prelude::*;
#
struct MyActor;
Expand All @@ -71,7 +71,7 @@ impl Handler<WhoAmI> for MyActor {
}

# fn main() {
# System::new("scratch");
# System::new();
# let addr = MyActor.start();
let who_addr = addr.do_send(WhoAmI{});
# }
Expand All @@ -88,8 +88,6 @@ of program shutdown. To do this you call [`Context::stop()`].
This is an adjusted Ping example that stops after 4 pings are received.

```rust
# extern crate actix;
# extern crate actix_rt;
# use actix::prelude::*;
# struct MyActor {
# count: usize,
Expand Down
8 changes: 4 additions & 4 deletions actix/src/sec-5-arbiter.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ wrapper to resolving async events in order. Consider we have two actors, A and
B, and we want to run an event on B only once a result from A is completed. We
can use `Arbiter::spawn` to assist with this task.

```rust
# extern crate actix;
```rust, should_panic
// FIXME: THIS EXAMPLE IS BROKEN, AND NEEDS TO BE FIXED
use actix::prelude::*;

struct SumActor {}
Expand Down Expand Up @@ -87,7 +87,7 @@ impl Handler<Display> for DisplayActor {
}

fn main() {
let system = System::new("single-arbiter-example");
let system = System::new();

// Define an execution flow using futures
let execution = async {
Expand Down Expand Up @@ -115,7 +115,7 @@ fn main() {
};

// Spawn the future onto the current Arbiter/event loop
Arbiter::spawn(execution);
actix_rt::spawn(execution);

// We only want to do one computation in this example, so we
// shut down the `System` which will stop any Arbiters within
Expand Down
6 changes: 2 additions & 4 deletions actix/src/sec-6-sync-arbiter.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ When implementing your Actor to be run on a SyncArbiter, it requires that your A
Context is changed from `Context` to `SyncContext`.

```rust
# extern crate actix;
use actix::prelude::*;

struct MySyncActor;
Expand All @@ -28,7 +27,7 @@ impl Actor for MySyncActor {
}
#
# fn main() {
# System::new("test");
# System::new();
# }
```

Expand All @@ -39,7 +38,6 @@ our `SyncArbiter`. We can only control the number of threads at SyncArbiter crea
time - we can't add/remove threads later.

```rust
# extern crate actix;
use actix::prelude::*;

struct MySyncActor;
Expand All @@ -49,7 +47,7 @@ impl Actor for MySyncActor {
}

# fn main() {
# System::new("test");
# System::new();
let addr = SyncArbiter::start(2, || MySyncActor);
# }
```
Expand Down