Skip to content

Example on https://riker.rs/actors/ does not compile #57

Description

@werner291

Hello,

the example here (found on https://riker.rs/actors/):

use std::time::Duration;
use riker::actors::*;

struct MyActor;

// implement the Actor trait
impl Actor for MyActor {
    type Msg = String;

    fn recv(&mut self,
            _ctx: &Context<String>,
            msg: String,
            _sender: Sender) {

        println!("Received: {}", msg);
    }
}

// start the system and create an actor
fn main() {
    let sys = ActorSystem::new().unwrap();

    let my_actor = sys.actor_of::<MyActor>("my-actor").unwrap();

    my_actor.tell("Hello my actor!".to_string(), None);

    // force main to wait before exiting program
    std::thread::sleep(Duration::from_millis(500));
}

does not compile, because:

error[E0277]: the trait bound `MyActor: Default` is not satisfied
  --> src/main.rs:23:24
   |
23 |     let my_actor = sys.actor_of::<MyActor>("my-actor").unwrap();
   |                        ^^^^^^^^ the trait `Default` is not implemented for `MyActor`
   |
   = note: required because of the requirements on the impl of `ActorFactory` for `MyActor`

This is on riker = "0.4", with cargo 1.50.0 (f04e7fab7 2021-02-04) and rustc 1.50.0 (cb75ad5db 2021-02-10).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions