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 BufWriter::buffer method #55211

Merged
merged 4 commits into from
Nov 15, 2018
Merged

Add BufWriter::buffer method #55211

merged 4 commits into from
Nov 15, 2018

Conversation

fintelia
Copy link
Contributor

CC #45323

@rust-highfive
Copy link
Collaborator

r? @shepmaster

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 19, 2018
@fintelia
Copy link
Contributor Author

@shepmaster Does this PR look reasonable?

/// ```
#[unstable(feature = "bufreader_buffer", issue = "45323")]
pub fn buffer(&self) -> &[u8] {
&self.buf[..]
Copy link
Member

Choose a reason for hiding this comment

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

Nit: This can just be &self.buf.

@sfackler
Copy link
Member

Could you add a simple test? Looks good otherwise!

@shepmaster
Copy link
Member

Sorry, I was away at a conference and let this drop off my radar.

add a simple test

You can use BufReader::new(&b"abcd"[..]); to get a very lightweight instance of a BufReader, FWIW.

@shepmaster
Copy link
Member

BufReader::new(&b"abcd"[..]); to get a very lightweight instance of a BufReader

Of course, I meant BufWriter::new(Vec::new()), not sure why I started talking about readers...

@fintelia
Copy link
Contributor Author

Is this ready for merging at this point?

/// use std::io::BufWriter;
/// use std::net::TcpStream;
///
/// let mut buf_writer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap());
Copy link
Member

Choose a reason for hiding this comment

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

This mut is unneeded for this example, right?

Copy link
Member

Choose a reason for hiding this comment

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

I think most other examples return a result to avoid the unwrap:

fn main() -> std::io::Result<()> {
    let buf_writer = BufWriter::new(TcpStream::connect("127.0.0.1:34254")?);

Check to see what the prevailing pattern is and follow that, please.

let b: &[_] = &[5, 6, 7];
assert_eq!(buf, b);
assert_eq!(buf, [5, 6, 7]);
assert_eq!(*reader.buffer(), []);
Copy link
Member

Choose a reason for hiding this comment

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

These * don't seem to be needed — why did you have to add them?

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-5.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
travis_time:end:01988a04:start=1541093667286994812,finish=1541093721096541729,duration=53809546917
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#Pull-Requests-and-Security-Restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
Setting environment variables from .travis.yml
$ export IMAGE=x86_64-gnu-llvm-5.0
---
[00:53:19] .................................................................................................... 100/4983
[00:53:22] .................................................................................................... 200/4983
[00:53:25] ...........................................................................................ii....... 300/4983
[00:53:27] .........................................................................................iii........ 400/4983
[00:53:30] iiiiiiii.iii...........................iii...........................................i...........i.. 500/4983
[00:53:38] .................................................................................................... 700/4983
[00:53:44] ..................................................................i...........i..................... 800/4983
[00:53:47] ....................................................................................iiiii........... 900/4983
[00:53:51] .................................................................................................... 1000/4983
---
[00:54:28] .................................................................................................... 2200/4983
[00:54:32] .................................................................................................... 2300/4983
[00:54:36] .................................................................................................... 2400/4983
[00:54:40] .................................................................................................... 2500/4983
[00:54:44] ...................................................................iiiiiiiii........................ 2600/4983
[00:54:51] ..................ii................................................................................ 2800/4983
[00:54:54] .................................................................................................... 2900/4983
[00:54:58] .................................................................................................... 3000/4983
[00:55:00] .............i...................................................................................... 3100/4983
---
travis_time:start:test_codegen
Check compiletest suite=codegen mode=codegen (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
[01:08:47] 
[01:08:47] running 115 tests
[01:08:50] i..ii...iii..iii.....i...i.........i..iii...........i.....i.....ii...i..i.ii..............i...ii..ii 100/115
[01:08:51] .i....iiii.....
[01:08:51] 
[01:08:51]  finished in 3.684
[01:08:51] travis_fold:end:test_codegen

---
travis_time:start:test_debuginfo
Check compiletest suite=debuginfo mode=debuginfo-both (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
[01:09:06] 
[01:09:06] running 118 tests
[01:09:31] .iiiii...i.....i..i...i..i.i..i.i..i.....i..i....i..........iiii.........i.i....i...i.......ii.i.i.i 100/118
[01:09:35] ......iii.i.....ii
[01:09:35] 
[01:09:35]  finished in 29.329
[01:09:35] travis_fold:end:test_debuginfo

---
[01:28:13] travis_fold:start:test_stage1-std
travis_time:start:test_stage1-std
Testing std stage1 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
[01:28:13]    Compiling std v0.0.0 (/checkout/src/libstd)
[01:28:23] error[E0277]: can't compare `&realstd::vec::Vec<u8>` with `[{integer}; 2]`
[01:28:23]      |
[01:28:23]      |
[01:28:23] 1101 |         assert_eq!(writer.get_ref(), [0, 1]);
[01:28:23]      |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `&realstd::vec::Vec<u8> == [{integer}; 2]`
[01:28:23]      |
[01:28:23]      = help: the trait `core::cmp::PartialEq<[{integer}; 2]>` is not implemented for `&realstd::vec::Vec<u8>`
[01:28:23] 
[01:28:23] 
[01:28:23] error[E0277]: can't compare `&realstd::vec::Vec<u8>` with `[{integer}; 2]`
[01:28:23]      |
[01:28:23]      |
[01:28:23] 1105 |         assert_eq!(writer.get_ref(), [0, 1]);
[01:28:23]      |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `&realstd::vec::Vec<u8> == [{integer}; 2]`
[01:28:23]      |
[01:28:23]      = help: the trait `core::cmp::PartialEq<[{integer}; 2]>` is not implemented for `&realstd::vec::Vec<u8>`
[01:28:23] 
[01:28:23] 
[01:28:23] error[E0277]: can't compare `&realstd::vec::Vec<u8>` with `[{integer}; 2]`
[01:28:23]      |
[01:28:23]      |
[01:28:23] 1109 |         assert_eq!(writer.get_ref(), [0, 1]);
[01:28:23]      |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `&realstd::vec::Vec<u8> == [{integer}; 2]`
[01:28:23]      |
[01:28:23]      = help: the trait `core::cmp::PartialEq<[{integer}; 2]>` is not implemented for `&realstd::vec::Vec<u8>`
[01:28:23] 
[01:28:23] 
[01:28:23] error[E0277]: can't compare `&realstd::vec::Vec<u8>` with `[{integer}; 4]`
[01:28:23]      |
[01:28:23]      |
[01:28:23] 1113 |         assert_eq!(writer.get_ref(), [0, 1, 2, 3]);
[01:28:23]      |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `&realstd::vec::Vec<u8> == [{integer}; 4]`
[01:28:23]      |
[01:28:23]      = help: the trait `core::cmp::PartialEq<[{integer}; 4]>` is not implemented for `&realstd::vec::Vec<u8>`
[01:28:23] 
[01:28:23] 
[01:28:23] error[E0277]: can't compare `&realstd::vec::Vec<u8>` with `[{integer}; 4]`
[01:28:23]      |
[01:28:23]      |
[01:28:23] 1118 |         assert_eq!(writer.get_ref(), [0, 1, 2, 3]);
[01:28:23]      |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `&realstd::vec::Vec<u8> == [{integer}; 4]`
[01:28:23]      |
[01:28:23]      = help: the trait `core::cmp::PartialEq<[{integer}; 4]>` is not implemented for `&realstd::vec::Vec<u8>`
[01:28:23] 
[01:28:23] 
[01:28:23] error[E0277]: can't compare `&realstd::vec::Vec<u8>` with `[{integer}; 6]`
[01:28:23]      |
[01:28:23]      |
[01:28:23] 1122 |         assert_eq!(writer.get_ref(), [0, 1, 2, 3, 4, 5]);
[01:28:23]      |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `&realstd::vec::Vec<u8> == [{integer}; 6]`
[01:28:23]      |
[01:28:23]      = help: the trait `core::cmp::PartialEq<[{integer}; 6]>` is not implemented for `&realstd::vec::Vec<u8>`
[01:28:23] 
[01:28:23] 
[01:28:23] error[E0277]: can't compare `&realstd::vec::Vec<u8>` with `[{integer}; 9]`
[01:28:23]      |
[01:28:23]      |
[01:28:23] 1126 |         assert_eq!(writer.get_ref(), [0, 1, 2, 3, 4, 5, 6, 7, 8]);
[01:28:23]      |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `&realstd::vec::Vec<u8> == [{integer}; 9]`
[01:28:23]      |
[01:28:23]      = help: the trait `core::cmp::PartialEq<[{integer}; 9]>` is not implemented for `&realstd::vec::Vec<u8>`
[01:28:23] 
[01:28:23] 
[01:28:23] error[E0277]: can't compare `&realstd::vec::Vec<u8>` with `[{integer}; 12]`
[01:28:23]      |
[01:28:23]      |
[01:28:23] 1130 |         assert_eq!(writer.get_ref(), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]);
[01:28:23]      |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `&realstd::vec::Vec<u8> == [{integer}; 12]`
[01:28:23]      |
[01:28:23]      = help: the trait `core::cmp::PartialEq<[{integer}; 12]>` is not implemented for `&realstd::vec::Vec<u8>`
[01:28:23] 
[01:28:23] 
[01:28:23] error[E0277]: can't compare `&realstd::vec::Vec<u8>` with `[{integer}; 12]`
[01:28:23]      |
[01:28:23]      |
[01:28:23] 1134 |         assert_eq!(writer.get_ref(), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]);
[01:28:23]      |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `&realstd::vec::Vec<u8> == [{integer}; 12]`
[01:28:23]      |
[01:28:23]      = help: the trait `core::cmp::PartialEq<[{integer}; 12]>` is not implemented for `&realstd::vec::Vec<u8>`
[01:28:23] 
[01:28:30] error: aborting due to 9 previous errors
[01:28:30] 
[01:28:30] For more information about this error, try `rustc --explain E0277`.
[01:28:30] For more information about this error, try `rustc --explain E0277`.
[01:28:30] error: Could not compile `std`.
[01:28:30] 
[01:28:30] To learn more, run the command again with --verbose.
[01:28:30] 
[01:28:30] 
[01:28:30] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "test" "--target" "x86_64-unknown-linux-gnu" "-j" "4" "--release" "--locked" "--color" "always" "--features" "panic-unwind jemalloc backtrace" "--manifest-path" "/checkout/src/libstd/Cargo.toml" "-p" "std" "--" "--quiet"
[01:28:30] 
[01:28:30] 
[01:28:30] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[01:28:30] Build completed unsuccessfully in 0:39:03
[01:28:30] Build completed unsuccessfully in 0:39:03
[01:28:30] make: *** [check] Error 1
[01:28:30] Makefile:58: recipe for target 'check' failed

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:00927a04
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@shepmaster
Copy link
Member

Looks OK to me — care to hit it with a rebase and force-push and we'll be on our way!

@TimNN
Copy link
Contributor

TimNN commented Nov 13, 2018

Ping from triage @shepmaster: it looks like the PR has been rebased and is ready for a final review.

@shepmaster
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Nov 13, 2018

📌 Commit 59a0309 has been approved by shepmaster

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 13, 2018
@shepmaster
Copy link
Member

Argh; I forget GH doesn't ping for force pushes — sorry!

kennytm added a commit to kennytm/rust that referenced this pull request Nov 14, 2018
bors added a commit that referenced this pull request Nov 15, 2018
Rollup of 16 pull requests

Successful merges:

 - #54906 (Reattach all grandchildren when constructing specialization graph.)
 - #55182 (Redox: Update to new changes)
 - #55211 (Add BufWriter::buffer method)
 - #55507 (Add link to std::mem::size_of to size_of intrinsic documentation)
 - #55530 (Speed up String::from_utf16)
 - #55556 (Use `Mmap` to open the rmeta file.)
 - #55622 (NetBSD: link libstd with librt in addition to libpthread)
 - #55827 (A few tweaks to iterations/collecting)
 - #55901 (fix various typos in doc comments)
 - #55926 (Change sidebar selector to fix compatibility with docs.rs)
 - #55930 (A handful of hir tweaks)
 - #55932 (core/char: Speed up `to_digit()` for `radix <= 10`)
 - #55935 (appveyor: Use VS2017 for all our images)
 - #55936 (save-analysis: be even more aggressive about ignorning macro-generated defs)
 - #55948 (submodules: update clippy from d8b4269 to 7e0ddef)
 - #55956 (add tests for some fixed ICEs)
pietroalbini added a commit to pietroalbini/rust that referenced this pull request Nov 15, 2018
bors added a commit that referenced this pull request Nov 15, 2018
Rollup of 17 pull requests

Successful merges:

 - #55182 (Redox: Update to new changes)
 - #55211 (Add BufWriter::buffer method)
 - #55507 (Add link to std::mem::size_of to size_of intrinsic documentation)
 - #55530 (Speed up String::from_utf16)
 - #55556 (Use `Mmap` to open the rmeta file.)
 - #55622 (NetBSD: link libstd with librt in addition to libpthread)
 - #55750 (Make `NodeId` and `HirLocalId` `newtype_index`)
 - #55778 (Wrap some query results in `Lrc`.)
 - #55781 (More precise spans for temps and their drops)
 - #55785 (Add mem::forget_unsized() for forgetting unsized values)
 - #55852 (Rewrite `...` as `..=` as a `MachineApplicable` 2018 idiom lint)
 - #55865 (Unix RwLock: avoid racy access to write_locked)
 - #55901 (fix various typos in doc comments)
 - #55926 (Change sidebar selector to fix compatibility with docs.rs)
 - #55930 (A handful of hir tweaks)
 - #55932 (core/char: Speed up `to_digit()` for `radix <= 10`)
 - #55956 (add tests for some fixed ICEs)

Failed merges:

r? @ghost
@bors bors merged commit 59a0309 into rust-lang:master Nov 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants