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

Adding String and Vec Body Types #33

Merged
merged 9 commits into from
Nov 11, 2018
Merged

Adding String and Vec Body Types #33

merged 9 commits into from
Nov 11, 2018

Conversation

tzilist
Copy link
Contributor

@tzilist tzilist commented Nov 9, 2018

Apologies in advance - I am extremely new to rust.

Hopefully this PR closes #7 and also adds some examples on how to extract different body types

Let me know if you'd like any changes!

}

async fn echo_string(msg: String) -> String {
println!("String: {}", msg);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we shouldn't do println!() in examples, rather I think it would be nice to show an example with logging.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed! Logging middleware hasn't been implemented yet. Should I implement one in the example? Or should we wait until that is done to do that here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I just saw that on #8. I would also like to try out experimenting with logging if I can. Maybe can just leave this be for now.

src/body.rs Outdated
}

impl <S: 'static> Extract<S> for String {
Copy link
Contributor

Choose a reason for hiding this comment

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

@tzilist I think it would be nice to rustfmt the file here, it uses impl<S: 'static> ... rather than impl <S: 'static>.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done! :)

src/body.rs Outdated

FutureObj::new(Box::new(async move {
fn mk_err<T>(_: T) -> Response { StatusCode::BAD_REQUEST.into_response() }
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we extract this out in it's own function? Since I saw it declared multiple times in different functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Was wondering that myself. Curious if we should wait for the config to be solidified (where we can state the default failure response) before worrying too much about this?

@aturon
Copy link
Collaborator

aturon commented Nov 9, 2018

Thanks for this PR!

One suggestion: I think that tying these extractors directly to the String and Vec types could be a bit confusing, because for the endpoint the argument just looks like... a String.

I think it'd be better to do something similar to Json<T>:

pub struct BodyString(pub String);
pub struct BodyBytes(pub Vec<u8>);

(feel free to improve the names)

@tzilist
Copy link
Contributor Author

tzilist commented Nov 9, 2018

@aturon I have taken your suggestion and added several types Str, StrLossy and Bytes. I am hoping that that is clear when setting the types for the actual endpoints, i.e.

fn endpoint(req_body: body::Bytes) 

or

fn endpoint(req_body: body::StrLossy)

Let me know what you think!

Edit: It would appear rustfmt has formatted the entire project. I'll try and fix this later, sorry about that.

@aturon
Copy link
Collaborator

aturon commented Nov 9, 2018

@tzilist Looks great! Once the rustfmt stuff is fixed, should be good to go!

@tzilist
Copy link
Contributor Author

tzilist commented Nov 10, 2018

@aturon Ok should be good to go now, thanks for your patience :)

@aturon
Copy link
Collaborator

aturon commented Nov 10, 2018

thanks @tzilist, but it looks like there's still a fair amount of reformatting to 2-space indents.

@tzilist
Copy link
Contributor Author

tzilist commented Nov 10, 2018

@aturon Sorry! Ok, now it should be good...

@tzilist
Copy link
Contributor Author

tzilist commented Nov 11, 2018

Updated this PR to reflect upstream changes.

@tzilist
Copy link
Contributor Author

tzilist commented Nov 11, 2018

And formatting check now works :)

@aturon aturon merged commit 2995b44 into http-rs:master Nov 11, 2018
@aturon
Copy link
Collaborator

aturon commented Nov 11, 2018

Thank you, merged!

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.

Add more body types
3 participants