mirror of
https://github.com/actix/actix-website
synced 2024-11-23 16:31:08 +01:00
Format example code in sec-3-address.md (#427)
* Format example code in sec-3-address.md * Remove unnecessary return type annotations in sec-3-address.md
This commit is contained in:
parent
fd0450917d
commit
b8555d96e8
@ -13,6 +13,7 @@ Here is an example of `Actor::start()` method usage. In this example `MyActor` a
|
|||||||
|
|
||||||
```rust
|
```rust
|
||||||
struct MyActor;
|
struct MyActor;
|
||||||
|
|
||||||
impl Actor for MyActor {
|
impl Actor for MyActor {
|
||||||
type Context = Context<Self>;
|
type Context = Context<Self>;
|
||||||
}
|
}
|
||||||
@ -113,7 +114,8 @@ impl Handler<Subscribe> for OrderEvents {
|
|||||||
/// Subscribe to ship message
|
/// Subscribe to ship message
|
||||||
impl Handler<Ship> for OrderEvents {
|
impl Handler<Ship> for OrderEvents {
|
||||||
type Result = ();
|
type Result = ();
|
||||||
fn handle(&mut self, msg: Ship, ctx: &mut Self::Context) -> Self::Result {
|
|
||||||
|
fn handle(&mut self, msg: Ship, ctx: &mut Self::Context) {
|
||||||
self.notify(msg.0);
|
self.notify(msg.0);
|
||||||
System::current().stop();
|
System::current().stop();
|
||||||
}
|
}
|
||||||
@ -121,25 +123,31 @@ impl Handler<Ship> for OrderEvents {
|
|||||||
|
|
||||||
/// Email Subscriber
|
/// Email Subscriber
|
||||||
struct EmailSubscriber;
|
struct EmailSubscriber;
|
||||||
|
|
||||||
impl Actor for EmailSubscriber {
|
impl Actor for EmailSubscriber {
|
||||||
type Context = Context<Self>;
|
type Context = Context<Self>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Handler<OrderShipped> for EmailSubscriber {
|
impl Handler<OrderShipped> for EmailSubscriber {
|
||||||
type Result = ();
|
type Result = ();
|
||||||
fn handle(&mut self, msg: OrderShipped, _ctx: &mut Self::Context) -> Self::Result {
|
|
||||||
|
fn handle(&mut self, msg: OrderShipped, _ctx: &mut Self::Context) {
|
||||||
println!("Email sent for order {}", msg.0)
|
println!("Email sent for order {}", msg.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// SMS Subscriber
|
||||||
struct SmsSubscriber;
|
struct SmsSubscriber;
|
||||||
|
|
||||||
impl Actor for SmsSubscriber {
|
impl Actor for SmsSubscriber {
|
||||||
type Context = Context<Self>;
|
type Context = Context<Self>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Handler<OrderShipped> for SmsSubscriber {
|
impl Handler<OrderShipped> for SmsSubscriber {
|
||||||
type Result = ();
|
type Result = ();
|
||||||
fn handle(&mut self, msg: OrderShipped, _ctx: &mut Self::Context) -> Self::Result {
|
|
||||||
|
fn handle(&mut self, msg: OrderShipped, _ctx: &mut Self::Context) {
|
||||||
println!("SMS sent for order {}", msg.0)
|
println!("SMS sent for order {}", msg.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,9 +158,11 @@ async fn main() -> Result<(), actix::MailboxError> {
|
|||||||
let email_subscriber = Subscribe(EmailSubscriber {}.start().recipient());
|
let email_subscriber = Subscribe(EmailSubscriber {}.start().recipient());
|
||||||
let sms_subscriber = Subscribe(SmsSubscriber {}.start().recipient());
|
let sms_subscriber = Subscribe(SmsSubscriber {}.start().recipient());
|
||||||
let order_event = OrderEvents::new().start();
|
let order_event = OrderEvents::new().start();
|
||||||
|
|
||||||
order_event.send(email_subscriber).await?;
|
order_event.send(email_subscriber).await?;
|
||||||
order_event.send(sms_subscriber).await?;
|
order_event.send(sms_subscriber).await?;
|
||||||
order_event.send(Ship(1)).await?;
|
order_event.send(Ship(1)).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
Loading…
Reference in New Issue
Block a user