gcmodule
gcmodule copied to clipboard
Box<dyn T>
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
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>.
https://github.com/quark-zju/gcmodule/blob/a8681f1452736d8ea6e14f352dff42736dee1e2f/src/trace_impls.rs#L89
But it's impl<T: Trace> Trace for Box<T>, not impl<T: Trace + Sized> Trace for Box<T>
By default trait bounds are Sized, unless explicitly specified + ?Sized, which allows unsized types.