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

Body constructor doc examples #139

Merged
merged 2 commits into from Jun 6, 2017

Conversation

Projects
None yet
2 participants
@jaemk
Copy link
Contributor

jaemk commented Jun 6, 2017

Addresses libz blitz (#120) "Examples for the Body constructors", issue #116

Body constructor doc examples
- Add doc examples for `Body` constructors
@seanmonstar
Copy link
Owner

seanmonstar left a comment

Thanks for the pull request! Just one thought about the text of the sized constructor.

src/body.rs Outdated
/// # use reqwest::Body;
/// # fn run() -> Result<(), Box<std::error::Error>> {
/// // &[u8] implements std::io::Read, and the source `s` has a
/// // 'static lifetime and a known number of bytes.

This comment has been minimized.

@seanmonstar

seanmonstar Jun 6, 2017

Owner

I think the example probably should address the point in the lines above, about how this constructor is useful if "we don't want to load the data in memory". If someone has a a bundle of bytes, it's actually better in to use Body::from().

This was originally added to allow someone to include the length with a File or similar.

let file = File::open("foo.txt")?;
let len = file.metadata()?.len();
let body = Body::sized(file, len);

This comment has been minimized.

@jaemk

jaemk Jun 6, 2017

Author Contributor

Woops, that makes more sense!

Body constructor doc examples
- Use a file & filesize in `Body::sized` example
- Point out the available `From` impls on `Body` for constructing
  reusable `Body`s
@jaemk

This comment has been minimized.

Copy link
Contributor Author

jaemk commented Jun 6, 2017

  • The sized constructor example is updated to use a File and it's Metadata.len()
  • The new constructor docs are updated to point out the available From impls that should be used for a set of known bytes.

@seanmonstar seanmonstar merged commit 006368f into seanmonstar:master Jun 6, 2017

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@seanmonstar

This comment has been minimized.

Copy link
Owner

seanmonstar commented Jun 6, 2017

Thanks!

@jaemk jaemk deleted the jaemk:docs branch Jun 7, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.