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

Box<dyn T> #8

Open
mio-19 opened this issue Apr 3, 2020 · 3 comments · May be fixed by #9
Open

Box<dyn T> #8

mio-19 opened this issue Apr 3, 2020 · 3 comments · May be fixed by #9

Comments

@mio-19
Copy link
Contributor

mio-19 commented Apr 3, 2020

I somehow got this error:

error[E0277]: the size for values of type `dyn Values` cannot be known at compilation time
  --> src/lib.rs:54:49
   |
54 |         self.unsafe_write(THREADED_OBJECT_SPACE.create(Box::new(x))).await;
   |                                                 ^^^^^^ doesn't have a size known at compile-time
   |
   = help: the trait `std::marker::Sized` is not implemented for `dyn Values`
   = note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
   = note: required because of the requirements on the impl of `_::_gcmodule::Trace` for `std::boxed::Box<dyn Values>`

https://github.com/The-Lingo/The-Lingo/blob/73f5827b7cc8da1b3ab264cc0d986c917c54abc4/rust/the-lingo/src/lib.rs

@quark-zju
Copy link
Owner

quark-zju commented Apr 3, 2020

The error is a bit confusing. It does not explain why dyn Values needs to be sized.

It is actually that Box<dyn Values> needs to implement Trace and in trace_impl.rs only Box<T: Trace + Sized> and Box<dyn Trace> implements Trace. Box<dyn Values> does not implement Trace, because dyn Values is not sized.

I think a solution would be adding a new type:

struct BoxValues(Box<dyn Values>);

Implement Trace on it, then use ThreadedCc<BoxValues>.

@mio-19
Copy link
Contributor Author

mio-19 commented Apr 4, 2020

impl<T: Trace> Trace for Box<T> {

But it's impl<T: Trace> Trace for Box<T>, not impl<T: Trace + Sized> Trace for Box<T>

@quark-zju
Copy link
Owner

By default trait bounds are Sized, unless explicitly specified + ?Sized, which allows unsized types.

@mio-19 mio-19 linked a pull request Apr 4, 2020 that will close this issue
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

Successfully merging a pull request may close this issue.

2 participants