about summary refs log tree commit diff
path: root/src/libstd/fmt/mod.rs
AgeCommit message (Collapse)AuthorLines
2014-05-15core: Inherit the std::fmt moduleAlex Crichton-1405/+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-26/+0
2014-05-08std: Extract format string parsing out of libstdAlex Crichton-20/+45
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: 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-3/+18
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-1/+2
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-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-04-18Replace all ~"" with "".to_owned()Richo Healey-12/+12
2014-04-14Use new attribute syntax in python files in src/etc too (#13478)Manish Goregaokar-2/+2
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-06De-~[] Mem{Reader,Writer}Steven Fackler-2/+2
2014-03-31std: Switch field privacy as necessaryAlex Crichton-12/+12
2014-03-25libstd: Document the following modules:Patrick Walton-30/+73
* 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-20rename std::vec -> std::sliceDaniel Micay-3/+3
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-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-5/+0
Replaces IterBytes with the new Hash, removing all trace of the old implementation.
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/+54
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
2014-02-15auto merge of #12298 : alexcrichton/rust/rustdoc-testing, r=sfacklerbors-6/+6
It's too easy to forget the `rust` tag to test something. Closes #11698
2014-02-15impl fmt::Pointer for &T and &mut TCorey Richardson-1/+11
2014-02-14Fix all code examplesAlex Crichton-6/+6
2014-02-11Move replace and swap to std::mem. Get rid of std::utilEdward Wang-5/+5
Also move Void to std::any, move drop to std::mem and reexport in prelude.
2014-02-08std::fmt: convert the formatting traits to a proper self.Huon Wilson-77/+77
Poly and String have polymorphic `impl`s and so require different method names.
2014-02-04Register new snapshotsAlex Crichton-5/+0
2014-02-03Fixing remaining warnings and errors throughoutAlex Crichton-18/+9
2014-02-03std: Fixing all documentationAlex Crichton-6/+16
* Stop referencing io_error * Start changing "Failure" sections to "Error" sections * Update all doc examples to work.
2014-02-03std: Remove io::io_errorAlex Crichton-86/+92
* 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-02-02Remove the SNAP line to work around #11985.Huon Wilson-2/+2
2014-02-02std::fmt: prepare to convert the formatting traits to methods, and workHuon Wilson-0/+35
around the lack of UFCS. The further work is pending a snapshot, to avoid putting #[cfg(stage0)] attributes on all the traits and duplicating them.
2014-02-02std: rename fmt::Default to `Show`.Huon Wilson-8/+27
This is a better name with which to have a #[deriving] mode. Decision in: https://github.com/mozilla/rust/wiki/Meeting-weekly-2014-01-28
2014-02-02libextra: Remove `@str` from all the librariesPatrick Walton-1/+0
2014-01-26Removed all instances of XXX in preparation for relaxing of FIXME ruleSalem Talha-4/+4