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

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

Open
werner291 opened this issue Feb 14, 2021 · 1 comment
Open

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

werner291 opened this issue Feb 14, 2021 · 1 comment

Comments

@werner291
Copy link

werner291 commented Feb 14, 2021

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).

@werner291
Copy link
Author

Simply implementing as follows seems to work:

impl Default for MyActor {
    fn default() -> Self {
        Self
    }
}

However, it's probably a good idea to add some text about how actors are instantiated, since Riker manages the lifetime of the actors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant