-
Notifications
You must be signed in to change notification settings - Fork 321
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
Conversation
examples/body_types.rs
Outdated
} | ||
|
||
async fn echo_string(msg: String) -> String { | ||
println!("String: {}", msg); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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>
.
There was a problem hiding this comment.
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() } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
Thanks for this PR! One suggestion: I think that tying these extractors directly to the I think it'd be better to do something similar to pub struct BodyString(pub String);
pub struct BodyBytes(pub Vec<u8>); (feel free to improve the names) |
@aturon I have taken your suggestion and added several types fn endpoint(req_body: body::Bytes) or fn endpoint(req_body: body::StrLossy) Let me know what you think! Edit: It would appear |
@tzilist Looks great! Once the rustfmt stuff is fixed, should be good to go! |
@aturon Ok should be good to go now, thanks for your patience :) |
thanks @tzilist, but it looks like there's still a fair amount of reformatting to 2-space indents. |
@aturon Sorry! Ok, now it should be good... |
Updated this PR to reflect upstream changes. |
And formatting check now works :) |
Thank you, merged! |
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!