summary refs log tree commit diff
path: root/src/libstd/io/mem.rs
AgeCommit message (Collapse)AuthorLines
2014-03-22std: Add an I/O reader method to fill a bufferAlex Crichton-2/+16
I've found a common use case being to fill a slice (not an owned vector) completely with bytes. It's posible for short reads to happen, and if you're trying to get an exact number of bytes then this helper will be useful.
2014-03-20rename std::vec -> std::sliceDaniel Micay-7/+7
Closes #12702
2014-02-28std: Change assert_eq!() to use {} instead of {:?}Alex Crichton-14/+14
Formatting via reflection has been a little questionable for some time now, and it's a little unfortunate that one of the standard macros will silently use reflection when you weren't expecting it. This adds small bits of code bloat to libraries, as well as not always being necessary. In light of this information, this commit switches assert_eq!() to using {} in the error message instead of {:?}. In updating existing code, there were a few error cases that I encountered: * It's impossible to define Show for [T, ..N]. I think DST will alleviate this because we can define Show for [T]. * A few types here and there just needed a #[deriving(Show)] * Type parameters needed a Show bound, I often moved this to `assert!(a == b)` * `Path` doesn't implement `Show`, so assert_eq!() cannot be used on two paths. I don't think this is much of a regression though because {:?} on paths looks awful (it's a byte array). Concretely speaking, this shaved 10K off a 656K binary. Not a lot, but sometime significant for smaller binaries.
2014-02-28std: Improve some I/O documentationAlex Crichton-0/+2
This lowers the #[allow(missing_doc)] directive into some of the lower modules which are less mature. Most I/O modules now require comprehensive documentation.
2014-02-20Mass rename if_ok! to try!Alex Crichton-4/+4
This "bubble up an error" macro was originally named if_ok! in order to get it landed, but after the fact it was discovered that this name is not exactly desirable. The name `if_ok!` isn't immediately clear that is has much to do with error handling, and it doesn't look fantastic in all contexts (if if_ok!(...) {}). In general, the agreed opinion about `if_ok!` is that is came in as subpar. The name `try!` is more invocative of error handling, it's shorter by 2 letters, and it looks fitting in almost all circumstances. One concern about the word `try!` is that it's too invocative of exceptions, but the belief is that this will be overcome with documentation and examples. Close #12037
2014-02-11Finalize the Seek APIAlex Crichton-26/+73
This adopts the rules posted in #10432: 1. If a seek position is negative, then an error is generated 2. Seeks beyond the end-of-file are allowed. Future writes will fill the gap with data and future reads will return errors. 3. Seeks within the bounds of a file are fine. Closes #10432
2014-02-08Fix infinite loop in BufReader::read_until.Q.P.Liu-1/+9
2014-02-08Fix infinite loop in MemReader::read_until.Q.P.Liu-1/+9
2014-02-03std: Fixing all documentationAlex Crichton-4/+8
* Stop referencing io_error * Start changing "Failure" sections to "Error" sections * Update all doc examples to work.
2014-02-03std: Fix tests with io_error usageAlex Crichton-77/+74
2014-02-03std: Remove io::io_errorAlex Crichton-27/+34
* All I/O now returns IoResult<T> = Result<T, IoError> * All formatting traits now return fmt::Result = IoResult<()> * The if_ok!() macro was added to libstd
2014-01-28Rename OwnedCopyableVector to OwnedCloneableVectorVirgile Andreani-1/+1
2014-01-17auto merge of #11598 : alexcrichton/rust/io-export, r=brsonbors-21/+52
* Reexport io::mem and io::buffered structs directly under io, make mem/buffered private modules * Remove with_mem_writer * Remove DEFAULT_CAPACITY and use DEFAULT_BUF_SIZE (in io::buffered) cc #11119
2014-01-17Tweak the interface of std::ioAlex Crichton-21/+52
* Reexport io::mem and io::buffered structs directly under io, make mem/buffered private modules * Remove with_mem_writer * Remove DEFAULT_CAPACITY and use DEFAULT_BUF_SIZE (in io::buffered)
2014-01-15Issue #3511 - Rationalize temporary lifetimes.Niko Matsakis-2/+4
Major changes: - Define temporary scopes in a syntax-based way that basically defaults to the innermost statement or conditional block, except for in a `let` initializer, where we default to the innermost block. Rules are documented in the code, but not in the manual (yet). See new test run-pass/cleanup-value-scopes.rs for examples. - Refactors Datum to better define cleanup roles. - Refactor cleanup scopes to not be tied to basic blocks, permitting us to have a very large number of scopes (one per AST node). - Introduce nascent documentation in trans/doc.rs covering datums and cleanup in a more comprehensive way.
2014-01-09Add eof to MemReader and BufReaderSteven Fackler-2/+12
It's easy to figure out and useful as a sanity check sometimes.
2014-01-09Remove eof() from io::ReaderAlex Crichton-10/+2
2014-01-08Remove the io::Decorator traitAlex Crichton-21/+30
This is just an unnecessary trait that no one's ever going to parameterize over and it's more useful to just define the methods directly on the types themselves. The implementors of this type almost always don't want inner_mut_ref() but they're forced to define it as well.
2014-01-04Restore Writer.write_char, see #10861.Gareth Smith-0/+10
2014-01-03Add read_to_str and write_{str, line}Alex Crichton-0/+20
These methods are sorely needed on readers and writers, and I believe that the encoding story should be solved with composition. This commit adds back the missed functions when reading/writing strings onto generic Readers/Writers.
2013-12-15std::vec: remove unnecessary count parameter on {bytes,Huon Wilson-6/+4
raw}::copy_memory. Slices carry their length with them, so we can just use that information.
2013-12-11Make 'self lifetime illegal.Erik Price-11/+11
Also remove all instances of 'self within the codebase. This fixes #10889.
2013-12-01std::io::mem: add a with_capacity constructor to MemWriter.Huon Wilson-1/+7
This allows one to reduce the number of reallocs of the internal buffer if one has an approximate idea of the size of the final output.
2013-11-26test: Remove non-procedure uses of `do` from compiletest, libstd tests,Patrick Walton-3/+3
compile-fail tests, run-fail tests, and run-pass tests.
2013-11-19libstd: Change all uses of `&fn(A)->B` over to `|A|->B` in libstdPatrick Walton-1/+1
2013-11-17auto merge of #10466 : alexcrichton/rust/issue-10334, r=cmrbors-19/+29
These commits create a `Buffer` trait in the `io` module which represents an I/O reader which is internally buffered. This abstraction is used to reasonably implement `read_line` and `read_until` along with at least an ok implementation of `read_char` (although I certainly haven't benchmarked `read_char`).
2013-11-16Implement read_char on the Buffer traitAlex Crichton-0/+16
2013-11-13Introduce an io::Buffer traitAlex Crichton-19/+13
This trait is meant to abstract whether a reader is actually implemented with an underlying buffer. For all readers which are implemented as such, we can efficiently implement things like read_char, read_line, read_until, etc. There are two required methods for managing the internal buffer, and otherwise read_line and friends can all become default methods. Closes #10334
2013-11-13Implemented BufWriterZach Kamsler-10/+99
Filled in the implementations of Writer and Seek for BufWriter. It raises the io_error condition if a write cannot fit in the buffer. The Seek implementation for MemWriter, which was incorrectly using unsigned arithmatic to add signed offsets, has also been replaced.
2013-11-11Move std::rt::io to std::ioAlex Crichton-0/+308