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

Add more From conversions #101

Merged
merged 5 commits into from
Apr 23, 2020
Merged

Add more From conversions #101

merged 5 commits into from
Apr 23, 2020

Conversation

yoshuawuyts
Copy link
Member

@yoshuawuyts yoshuawuyts commented Apr 21, 2020

In the past we couldn't use Into<Response> in Tide's Endpoints because of the orphan rules. Tide now uses its own Response so we can move to deprecate that trait.

This patch adds the missing conversions currently used in Tide (src). This will make it easier to implement the conversions in Tide as well. Thanks!

@yoshuawuyts yoshuawuyts changed the title Body from Add more From conversions Apr 21, 2020
@jbr
Copy link
Member

jbr commented Apr 22, 2020

These look quite convenient!
Would it make sense / be possible to implement the impl<'a> From<&'a [u8]> for Response as a generic From<B> for Response where B: Into<Body> (or whatever the orphan-rule-allowed version of that is)?

@yoshuawuyts
Copy link
Member Author

@jbr done!

let mut res = Response::new(StatusCode::Ok);
res.set_body(b);
res.set_body(body);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a minor tweak, but this could be

impl<T> From<T> for Response
where
    T: Into<Body>,
{
    fn from(value: T) -> Self {
        let mut res = Response::new(StatusCode::Ok);
        res.set_body(value);
        res
    }
}

since replace_body does the .into::<Body>()

meta: is this sort of review useful?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jbr thanks heaps for suggesting this; yeah this is very useful!

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 this pull request may close these issues.

2 participants