From b8555d96e841c208c5c675d8f98fce56f17f3f48 Mon Sep 17 00:00:00 2001 From: Zirconium409122 <152716976+Zirconium419122@users.noreply.github.com> Date: Mon, 5 Aug 2024 12:56:11 +0200 Subject: [PATCH] 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 --- docs/actix/sec-3-address.md | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/docs/actix/sec-3-address.md b/docs/actix/sec-3-address.md index 0a8723f..33902e2 100644 --- a/docs/actix/sec-3-address.md +++ b/docs/actix/sec-3-address.md @@ -13,6 +13,7 @@ Here is an example of `Actor::start()` method usage. In this example `MyActor` a ```rust struct MyActor; + impl Actor for MyActor { type Context = Context; } @@ -113,7 +114,8 @@ impl Handler for OrderEvents { /// Subscribe to ship message impl Handler for OrderEvents { 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); System::current().stop(); } @@ -121,25 +123,31 @@ impl Handler for OrderEvents { /// Email Subscriber struct EmailSubscriber; + impl Actor for EmailSubscriber { type Context = Context; } impl Handler for EmailSubscriber { 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) } } + +/// SMS Subscriber struct SmsSubscriber; + impl Actor for SmsSubscriber { type Context = Context; } impl Handler for SmsSubscriber { 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) } @@ -150,9 +158,11 @@ async fn main() -> Result<(), actix::MailboxError> { let email_subscriber = Subscribe(EmailSubscriber {}.start().recipient()); let sms_subscriber = Subscribe(SmsSubscriber {}.start().recipient()); let order_event = OrderEvents::new().start(); + order_event.send(email_subscriber).await?; order_event.send(sms_subscriber).await?; order_event.send(Ship(1)).await?; + Ok(()) } ```