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

can not use Arc<dyn trait> with atom #14

Open
jiacai2050 opened this issue Nov 10, 2020 · 1 comment
Open

can not use Arc<dyn trait> with atom #14

jiacai2050 opened this issue Nov 10, 2020 · 1 comment

Comments

@jiacai2050
Copy link

Demo

trait Engine {
    fn eval(&self) -> String;
}

struct JSEngine {
    name: String,
}

impl Engine for JSEngine {
    fn eval(&self) -> String {
        "js eval".to_string()
    }
}

fn main() {
    let engine: Arc<dyn Engine> = Arc::new(JSEngine {
        name: "js1".to_string(),
    });
    println!("Results: {}", engine.eval());

    let shared_atom = Atom::new(engine);
}
error[E0277]: the size for values of type `dyn Engine` cannot be known at compilation time
  --> src/bin/main.rs:36:33
   |
36 |     let shared_atom = Atom::new(engine);
   |                                 ^^^^^^ doesn't have a size known at compile-time
   |
   = help: the trait `std::marker::Sized` is not implemented for `dyn Engine`
   = note: required because of the requirements on the impl of `atom::IntoRawPtr` for `std::sync::Arc<dyn Engine>`
   = note: required by `atom::Atom::<P>::new`

error[E0277]: the size for values of type `dyn Engine` cannot be known at compilation time
  --> src/bin/main.rs:36:23
   |
36 |     let shared_atom = Atom::new(engine);
   |                       ^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
   | 
  :::~/.cargo/registry/src/github.com-1ecc6299db9ec823/atom-0.4.0/src/lib.rs:29:8
   |
29 |     P: IntoRawPtr + FromRawPtr,
   |        ---------- required by this bound in `atom::Atom`
   |
   = help: the trait `std::marker::Sized` is not implemented for `dyn Engine`
   = note: required because of the requirements on the impl of `atom::IntoRawPtr` for `std::sync::Arc<dyn Engine>`

error: aborting due to 2 previous errors; 2 warnings emitted

For more information about this error, try `rustc --explain E0277`.
error: could not compile `foo`.

To learn more, run the command again with --verbose.


@jiacai2050 jiacai2050 changed the title can not use Arc<dyn trait> with atom can not use Arc<dyn trait> with atom :sad: Nov 10, 2020
@jiacai2050 jiacai2050 changed the title can not use Arc<dyn trait> with atom :sad: can not use Arc<dyn trait> with atom Nov 10, 2020
@jiacai2050
Copy link
Author

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