about summary refs log tree commit diff
path: root/src/libstd/condition.rs
AgeCommit message (Collapse)AuthorLines
2014-02-06Remove std::conditionAlex Crichton-349/+0
This has been a long time coming. Conditions in rust were initially envisioned as being a good alternative to error code return pattern. The idea is that all errors are fatal-by-default, and you can opt-in to handling the error by registering an error handler. While sounding nice, conditions ended up having some unforseen shortcomings: * Actually handling an error has some very awkward syntax: let mut result = None; let mut answer = None; io::io_error::cond.trap(|e| { result = Some(e) }).inside(|| { answer = Some(some_io_operation()); }); match result { Some(err) => { /* hit an I/O error */ } None => { let answer = answer.unwrap(); /* deal with the result of I/O */ } } This pattern can certainly use functions like io::result, but at its core actually handling conditions is fairly difficult * The "zero value" of a function is often confusing. One of the main ideas behind using conditions was to change the signature of I/O functions. Instead of read_be_u32() returning a result, it returned a u32. Errors were notified via a condition, and if you caught the condition you understood that the "zero value" returned is actually a garbage value. These zero values are often difficult to understand, however. One case of this is the read_bytes() function. The function takes an integer length of the amount of bytes to read, and returns an array of that size. The array may actually be shorter, however, if an error occurred. Another case is fs::stat(). The theoretical "zero value" is a blank stat struct, but it's a little awkward to create and return a zero'd out stat struct on a call to stat(). In general, the return value of functions that can raise error are much more natural when using a Result as opposed to an always-usable zero-value. * Conditions impose a necessary runtime requirement on *all* I/O. In theory I/O is as simple as calling read() and write(), but using conditions imposed the restriction that a rust local task was required if you wanted to catch errors with I/O. While certainly an surmountable difficulty, this was always a bit of a thorn in the side of conditions. * Functions raising conditions are not always clear that they are raising conditions. This suffers a similar problem to exceptions where you don't actually know whether a function raises a condition or not. The documentation likely explains, but if someone retroactively adds a condition to a function there's nothing forcing upstream users to acknowledge a new point of task failure. * Libaries using I/O are not guaranteed to correctly raise on conditions when an error occurs. In developing various I/O libraries, it's much easier to just return `None` from a read rather than raising an error. The silent contract of "don't raise on EOF" was a little difficult to understand and threw a wrench into the answer of the question "when do I raise a condition?" Many of these difficulties can be overcome through documentation, examples, and general practice. In the end, all of these difficulties added together ended up being too overwhelming and improving various aspects didn't end up helping that much. A result-based I/O error handling strategy also has shortcomings, but the cognitive burden is much smaller. The tooling necessary to make this strategy as usable as conditions were is much smaller than the tooling necessary for conditions. Perhaps conditions may manifest themselves as a future entity, but for now we're going to remove them from the standard library. Closes #9795 Closes #8968
2014-01-11Remove re-exports of std::io::stdio::{print, println} in the prelude.Brendan Zabarauskas-2/+2
The `print!` and `println!` macros are now the preferred method of printing, and so there is no reason to export the `stdio` functions in the prelude. The functions have also been replaced by their macro counterparts in the tutorial and other documentation so that newcomers don't get confused about what they should be using.
2013-12-23std: Fix all code examplesAlex Crichton-1/+11
2013-12-15std: fix spelling in docs.Huon Wilson-1/+1
2013-12-11Make 'self lifetime illegal.Erik Price-8/+8
Also remove all instances of 'self within the codebase. This fixes #10889.
2013-12-10librustpkg: Make `io::ignore_io_error()` use RAII; remove a few morePatrick Walton-3/+17
cells.
2013-11-26libstd: Fix Win32 and other bustage.Patrick Walton-5/+5
2013-11-26test: Remove non-procedure uses of `do` from compiletest, libstd tests,Patrick Walton-18/+18
compile-fail tests, run-fail tests, and run-pass tests.
2013-11-26librustc: Remove remaining uses of `&fn()` in favor of `||`.Patrick Walton-2/+2
2013-11-19libstd: Change all uses of `&fn(A)->B` over to `|A|->B` in libstdPatrick Walton-2/+2
2013-10-22Drop the '2' suffix from logging macrosAlex Crichton-19/+19
Who doesn't like a massive renaming?
2013-10-09option: rewrite the API to use compositionDaniel Micay-1/+1
2013-09-30std: Remove usage of fmt!Alex Crichton-20/+20
2013-09-25rustdoc: Change all code-blocks with a scriptAlex Crichton-8/+8
find src -name '*.rs' | xargs sed -i '' 's/~~~.*{\.rust}/```rust/g' find src -name '*.rs' | xargs sed -i '' 's/ ~~~$/ ```/g' find src -name '*.rs' | xargs sed -i '' 's/^~~~$/ ```/g'
2013-09-17Document a few undocumented modules in libstdAlex Crichton-33/+142
Hopefull this will make our libstd docs appear a little more "full".
2013-09-16switch Drop to `&mut self`Daniel Micay-1/+1
2013-09-04Another followup on #6009.Felix S. Klock II-1/+2
Odd that my earlier make checks did not catch this.
2013-08-01make `in` and `foreach` get treated as keywordsDaniel Micay-7/+7
2013-07-22new snapshotDaniel Micay-61/+0
2013-07-17librustc: Remove all uses of the `Copy` bound.Patrick Walton-5/+9
2013-07-17librustc: Remove all uses of "copy".Patrick Walton-1/+1
2013-07-14Purge the last remnants of the old TLS apiAlex Crichton-15/+68
Closes #3273
2013-07-11Remove all external requirements of `@` from TLSAlex Crichton-1/+1
Closes #6004
2013-07-09Rename local_data methods/types for less keystrokesAlex Crichton-9/+8
2013-07-09Change TLS to almost be able to contain owned typesAlex Crichton-1/+1
2013-06-25Change finalize -> drop.Luqman Aden-1/+1
2013-06-01Remove all uses of `pub impl`. rs=stylePatrick Walton-6/+6
2013-05-30Require documentation by default for libstdAlex Crichton-0/+2
Adds documentation for various things that I understand. Adds #[allow(missing_doc)] for lots of things that I don't understand.
2013-05-29librustc: Stop reexporting the standard modules from prelude.Patrick Walton-1/+2
2013-05-22libstd: Rename libcore to libstd and libstd to libextra; update makefiles.Patrick Walton-0/+217
This only changes the directory names; it does not change the "real" metadata names.