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

Data::<T>::into_inner requires T: Sized unnecessarily #2403

Closed
jarhodes314 opened this issue Oct 11, 2021 · 0 comments · Fixed by #2407
Closed

Data::<T>::into_inner requires T: Sized unnecessarily #2403

jarhodes314 opened this issue Oct 11, 2021 · 0 comments · Fixed by #2407
Labels
A-web project: actix-web C-improvement Category: an improvement to existing functionality good-first-issue easy to pick up for newcomers

Comments

@jarhodes314
Copy link
Contributor

Expected Behavior

I have some code that currently looks something like:

trait MyTrait {
   // ...
}

#[post("/some-path")]
pub async fn do_something(data: Data<dyn MyTrait>) {
    Container(data.into_inner()).do_something();
}

struct Container(Arc<dyn MyTrait>);

impl Container {
   // ...
}

However, this fails to compile since into_inner is only implemented for Data<T> (which has an implicit Sized bound on T).

Current Behavior

The above example doesn't compile since into_inner is only implemented for Data<T> (which has an implicit Sized bound on T). Instead, the handler has to call:

Container((*data).clone()).do_something()

to retrieve an owned Arc<dyn MyTrait>. This is both harder to read and unnecessary cloning.

Possible Solution

into_inner should be in an impl Data<T: ?Sized> block instead of impl Data.

@robjtede robjtede added C-improvement Category: an improvement to existing functionality good-first-issue easy to pick up for newcomers A-web project: actix-web labels Oct 11, 2021
jarhodes314 added a commit to jarhodes314/actix-web that referenced this issue Oct 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-web project: actix-web C-improvement Category: an improvement to existing functionality good-first-issue easy to pick up for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants