about summary refs log tree commit diff
path: root/src/libstd/fmt
AgeCommit message (Collapse)AuthorLines
2014-05-15core: Inherit the std::fmt moduleAlex Crichton-1968/+0
This commit moves all possible functionality from the standard library's string formatting utilities into the core library. This is a breaking change, due to a few tweaks in the semantics of formatting: 1. In order to break the dependency on the std::io module, a new trait, FormatWriter was introduced in core::fmt. This is the trait which is used (instead of Writer) to format data into a stream. 2. The new FormatWriter trait has one method, write(), which takes some bytes and can return an error, but the error contains very little information. The intent for this trait is for an adaptor writer to be used around the standard library's Writer trait. 3. The fmt::write{,ln,_unsafe} methods no longer take &mut io::Writer, but rather &mut FormatWriter. Since this trait is less common, all functions were removed except fmt::write, and it is not intended to be invoked directly. The main API-breaking change here is that the fmt::Formatter structure will no longer expose its `buf` field. All previous code writing directly to `f.buf` using writer methods or the `write!` macro will now instead use `f` directly. The Formatter object itself implements the `Writer` trait itself for convenience, although it does not implement the `FormatWriter` trait. The fallout of these changes will be in the following commits. [breaking-change]
2014-05-14auto merge of #14133 : db48x/rust/ord-for-mut-refs, r=alexcrichtonbors-0/+3
Also Show, which is useful in assertions. Fixes #14074
2014-05-14define Eq,TotalEq,Ord,TotalOrd for &mut TDaniel Brooks-0/+3
Also Show, which is useful in assertions. Fixes #14074
2014-05-12librustc: Remove all uses of `~str` from librustc.Patrick Walton-0/+14
2014-05-11core: Remove the cast moduleAlex Crichton-11/+11
This commit revisits the `cast` module in libcore and libstd, and scrutinizes all functions inside of it. The result was to remove the `cast` module entirely, folding all functionality into the `mem` module. Specifically, this is the fate of each function in the `cast` module. * transmute - This function was moved to `mem`, but it is now marked as #[unstable]. This is due to planned changes to the `transmute` function and how it can be invoked (see the #[unstable] comment). For more information, see RFC 5 and #12898 * transmute_copy - This function was moved to `mem`, with clarification that is is not an error to invoke it with T/U that are different sizes, but rather that it is strongly discouraged. This function is now #[stable] * forget - This function was moved to `mem` and marked #[stable] * bump_box_refcount - This function was removed due to the deprecation of managed boxes as well as its questionable utility. * transmute_mut - This function was previously deprecated, and removed as part of this commit. * transmute_mut_unsafe - This function doesn't serve much of a purpose when it can be achieved with an `as` in safe code, so it was removed. * transmute_lifetime - This function was removed because it is likely a strong indication that code is incorrect in the first place. * transmute_mut_lifetime - This function was removed for the same reasons as `transmute_lifetime` * copy_lifetime - This function was moved to `mem`, but it is marked `#[unstable]` now due to the likelihood of being removed in the future if it is found to not be very useful. * copy_mut_lifetime - This function was also moved to `mem`, but had the same treatment as `copy_lifetime`. * copy_lifetime_vec - This function was removed because it is not used today, and its existence is not necessary with DST (copy_lifetime will suffice). In summary, the cast module was stripped down to these functions, and then the functions were moved to the `mem` module. transmute - #[unstable] transmute_copy - #[stable] forget - #[stable] copy_lifetime - #[unstable] copy_mut_lifetime - #[unstable] [breaking-change]
2014-05-09Register new snapshotsAlex Crichton-37/+0
2014-05-08std: Extract format string parsing out of libstdAlex Crichton-1009/+80
This code does not belong in libstd, and rather belongs in a dedicated crate. In the future, the syntax::ext::format module should move to the fmt_macros crate (hence the name of the crate), but for now the fmt_macros crate will only contain the format string parser. The entire fmt_macros crate is marked #[experimental] because it is not meant for general consumption, only the format!() interface is officially supported, not the internals. This is a breaking change for anyone using the internals of std::fmt::parse. Some of the flags have moved to std::fmt::rt, while the actual parsing support has all moved to the fmt_macros library. [breaking-change]
2014-05-07core: Inherit the cell moduleAlex Crichton-0/+2
2014-05-07core: Add unwrap()/unwrap_err() methods to ResultAlex Crichton-0/+2
These implementations must live in libstd right now because the fmt module has not been migrated yet. This will occur in a later PR. Just to be clear, there are new extension traits, but they are not necessary once the std::fmt module has migrated to libcore, which is a planned migration in the future.
2014-05-07core: Inherit the result moduleAlex Crichton-0/+9
The unwrap()/unwrap_err() methods are temporarily removed, and will be added back in the next commit.
2014-05-07core: Inherit possible string functionalityAlex Crichton-4/+19
This moves as much allocation as possible from teh std::str module into core::str. This includes essentially all non-allocating functionality, mostly iterators and slicing and such. This primarily splits the Str trait into only having the as_slice() method, adding a new StrAllocating trait to std::str which contains the relevant new allocation methods. This is a breaking change if any of the methods of "trait Str" were overriden. The old functionality can be restored by implementing both the Str and StrAllocating traits. [breaking-change]
2014-05-07core: Inherit non-allocating slice functionalityAlex Crichton-0/+33
This commit adds a new trait, MutableVectorAllocating, which represents functions on vectors which can allocate. This is another extension trait to slices which should be removed once a lang item exists for the ~ allocation.
2014-05-07core: Inherit the cmp moduleAlex Crichton-0/+11
This removes the TotalOrd and TotalEq implementation macros, they will be added later to the numeric modules (where the other comparison implementations live).
2014-05-07core: Inherit the iter moduleAlex Crichton-0/+14
2014-05-07core: Inherit the option moduleAlex Crichton-0/+9
2014-05-07core: Inherit the tuple moduleAlex Crichton-0/+30
2014-05-07core: Inherit the unit moduleAlex Crichton-0/+6
2014-05-07core: Inherit the any moduleAlex Crichton-0/+8
2014-05-07core: Inherit the intrinsics moduleAlex Crichton-0/+7
2014-05-06librustc: Remove `~EXPR`, `~TYPE`, and `~PAT` from the language, exceptPatrick Walton-5/+7
for `~str`/`~[]`. Note that `~self` still remains, since I forgot to add support for `Box<self>` before the snapshot. How to update your code: * Instead of `~EXPR`, you should write `box EXPR`. * Instead of `~TYPE`, you should write `Box<Type>`. * Instead of `~PATTERN`, you should write `box PATTERN`. [breaking-change]
2014-05-05auto merge of #13912 : seanmonstar/rust/logrecord, r=alexcrichtonbors-0/+6
The logging macros now create a LogRecord, and pass that to the Logger. This will allow custom loggers to change the formatting, and possible filter on more properties of the log record. DefaultLogger's formatting was taken from Python's default formatting: `LEVEL:from: message` Also included: fmt::Arguments now implement Show, so they can be used to extend format strings. @alexcrichton r?
2014-05-05log: Logger receiveis a LogRecordSean McArthur-0/+6
The logging macros now create a LogRecord, and pass that to the Logger, instead of passing a `level` and `args`. The new signature is: trait Logger { fn log(&mut self, record: &LogRecord); } The LogRecord includes additional values that may be useful to custom loggers, and also allows for further expansion if not values are found useful. DefaultLogger's formatting was taken from Python's default formatting: `LEVEL:from: message` Also included: fmt::Arguments now implement Show, so they can be used to extend format strings. [breaking-change]
2014-05-02Replace most ~exprs with 'box'. #11779Brian Anderson-11/+11
2014-05-03Add lint check for negating uint literals and variables.Falco Hirschenberger-0/+2
See #11273 and #13318
2014-04-20Fix spelling mistakes in documentation and code.Joseph Crail-2/+2
2014-04-18Replace all ~"" with "".to_owned()Richo Healey-127/+128
2014-04-14Use new attribute syntax in python files in src/etc too (#13478)Manish Goregaokar-2/+2
2014-04-11auto merge of #13458 : huonw/rust/doc-signatures, r=alexcrichtonbors-7/+13
Add more type signatures to the docs; tweak a few of them. Someone reading the docs won't know what the types of various things are, so this adds them in a few meaningful places to help with comprehension. cc #13423.
2014-04-11Add more type signatures to the docs; tweak a few of them.Huon Wilson-7/+13
Someone reading the docs won't know what the types of various things are, so this adds them in a few meaningful places to help with comprehension. cc #13423.
2014-04-11libtest: rename `BenchHarness` to `Bencher`Liigo Zhuang-22/+22
Closes #12640
2014-04-10std,syntax: make std::fmt::parse use `Vec`s.Huon Wilson-58/+58
2014-04-06De-~[] Mem{Reader,Writer}Steven Fackler-2/+2
2014-04-01auto merge of #13115 : huonw/rust/rand-errors, r=alexcrichtonbors-10/+10
move errno -> IoError converter into std, bubble up OSRng errors Also adds a general errno -> `~str` converter to `std::os`, and makes the failure messages for the things using `OSRng` (e.g. (transitively) the task-local RNG, meaning hashmap initialisation failures aren't such a black box).
2014-04-01rand: bubble up IO messages futher.Huon Wilson-10/+10
The various ...Rng::new() methods can hit IO errors from the OSRng they use, and it seems sensible to expose them at a higher level. Unfortunately, writing e.g. `StdRng::new().unwrap()` gives a much poorer error message than if it failed internally, but this is a problem with all `IoResult`s.
2014-03-31std: Switch field privacy as necessaryAlex Crichton-42/+42
2014-03-28Convert most code to new inner attribute syntax.Brian Anderson-2/+2
Closes #2569
2014-03-25libstd: Document the following modules:Patrick Walton-46/+118
* native::io * std::char * std::fmt * std::fmt::parse * std::io * std::io::extensions * std::io::net::ip * std::io::net::udp * std::io::net::unix * std::io::pipe * std::num * std::num::f32 * std::num::f64 * std::num::strconv * std::os
2014-03-23use TotalEq for HashMapDaniel Micay-2/+2
Closes #5283
2014-03-20rename std::vec -> std::sliceDaniel Micay-4/+4
Closes #12702
2014-03-01std: Switch stdout/stderr to buffered by defaultAlex Crichton-2/+2
Similarly to #12422 which made stdin buffered by default, this commit makes the output streams also buffered by default. Now that buffered writers will flush their contents when they are dropped, I don't believe that there's no reason why the output shouldn't be buffered by default, which is what you want in 90% of cases. As with stdin, there are new stdout_raw() and stderr_raw() functions to get unbuffered streams to stdout/stderr.
2014-02-28std: Change assert_eq!() to use {} instead of {:?}Alex Crichton-1/+1
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-27Fix typo in doc of Binary trait in std::fmtMickaƫl Delahaye-1/+1
2014-02-23Remove all ToStr impls, add Show implsAlex Crichton-0/+10
This commit changes the ToStr trait to: impl<T: fmt::Show> ToStr for T { fn to_str(&self) -> ~str { format!("{}", *self) } } The ToStr trait has been on the chopping block for quite awhile now, and this is the final nail in its coffin. The trait and the corresponding method are not being removed as part of this commit, but rather any implementations of the `ToStr` trait are being forbidden because of the generic impl. The new way to get the `to_str()` method to work is to implement `fmt::Show`. Formatting into a `&mut Writer` (as `format!` does) is much more efficient than `ToStr` when building up large strings. The `ToStr` trait forces many intermediate allocations to be made while the `fmt::Show` trait allows incremental buildup in the same heap allocated buffer. Additionally, the `fmt::Show` trait is much more extensible in terms of interoperation with other `Writer` instances and in more situations. By design the `ToStr` trait requires at least one allocation whereas the `fmt::Show` trait does not require any allocations. Closes #8242 Closes #9806
2014-02-23auto merge of #12492 : huonw/rust/snapshots, r=alexcrichtonbors-7/+2
Replaces IterBytes with the new Hash, removing all trace of the old implementation.
2014-02-24Transition to new `Hash`, removing IterBytes and std::to_bytes.Huon Wilson-2/+2
2014-02-23Register snapshots.Huon Wilson-5/+0
2014-02-23rustdoc: Add syntax highlightingAlex Crichton-12/+12
This adds simple syntax highlighting based off libsyntax's lexer to be sure to stay up to date with rust's grammar. Some of the highlighting is a bit ad-hoc, but it definitely seems to get the job done! This currently doesn't highlight rustdoc-rendered function signatures and structs that are emitted to each page because the colors already signify what's clickable and I think we'd have to figure out a different scheme before colorizing them. This does, however, colorize all code examples and source code. Closes #11393
2014-02-22Decouple integer formatting from std::num::strconvBrendan Zabarauskas-121/+521
This works towards a complete rewrite and ultimate removal of the `std::num::strconv` module (see #6220), and the removal of the `ToStrRadix` trait in favour of using the `std::fmt` functionality directly. This should make for a cleaner API, encourage less allocation, and make the implementation far more comprehensible. The `Formatter::pad_integral` method has also been refactored make it easier to understand. The formatting tests for integers have been moved out of `run-pass/ifmt.rs` in order to provide more immediate feedback when building using `make check-stage2-std NO_REBUILD=1`. The benchmarks have been standardised between std::num::strconv and std::num::fmt to make it easier to compare the performance of the different implementations. Arbitrary radixes are now easier to use in format strings. For example: ~~~ assert_eq!(format!("{:04}", radix(3, 2)), ~"0011"); ~~~
2014-02-20Mass rename if_ok! to try!Alex Crichton-11/+11
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-16Minor documentation fixes in std::fmtSterling Greene-3/+3
* Change '...your own time' => '...your own type' * Fix typo in the Vector2D example