You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It should be possible to create web::Data from an Arc<dyn Xyz>.
Current Behavior
// trait T{}, struct A{}, impl T for A{}// This works as of nowlet test:Arc<Box<dynT>> = Arc::new(Box::new(A{}));let data = web::Data::from(test);// This should also work (see above with Sized)let test2:Arc<dynT> = Arc::new(A{});let data2 = web::Data::from(test2);
=> the size for values of type dyn T cannot be known at compilation time
Possible Solution
Add Data<T: ?Sized>
Extensions.insert uses TypeId::of::<T>, where in this case T is Data<T: ?Sized>.
To extract we can use extensions.get::<Data<dyn T>>()
Compare <T: ?Sized> (new version) with <T> (current version)
Context
I want to dynamically pass a Trait object to actix. This allows me to swap e.g. Service implementations with mock objects for unit tests.
Your Environment
Rust Version (I.e, output of rustc -V): rustc 1.46.0 (04488afe3 2020-08-24)
Actix Web Version: 3.0
Question is: Would it break anything else when adding ?Sized. Are there places relying on a known size? Quick glance shows that even the Arc is additionally Boxed in the Extensions HashMap.
The text was updated successfully, but these errors were encountered:
I did some testing and this idea seems to have merit. I think it would be okay as long as it is emphasized in the docs that only one (of each T) explicit dyn T is possible. Would welcome a PR to ascertain any wider impact.
Expected Behavior
It should be possible to create web::Data from an Arc<dyn Xyz>.
Current Behavior
=> the size for values of type
dyn T
cannot be known at compilation timePossible Solution
Add Data<T: ?Sized>
Extensions.insert uses TypeId::of::<T>, where in this case T is Data<T: ?Sized>.
To extract we can use extensions.get::<Data<dyn T>>()
Steps to Reproduce (for bugs)
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=7f31f526ea15a6c03ae768a900d822d0
Compare <T: ?Sized> (new version) with <T> (current version)
Context
I want to dynamically pass a Trait object to actix. This allows me to swap e.g. Service implementations with mock objects for unit tests.
Your Environment
rustc -V
): rustc 1.46.0 (04488afe3 2020-08-24)Question is: Would it break anything else when adding ?Sized. Are there places relying on a known size? Quick glance shows that even the Arc is additionally Boxed in the Extensions HashMap.
The text was updated successfully, but these errors were encountered: