Skip to content

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

@jiacai2050

Description

@jiacai2050

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.


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions