about summary refs log tree commit diff
path: root/src/libserialize
AgeCommit message (Collapse)AuthorLines
2015-01-03serialize: fix falloutJorge Aparicio-3/+6
2015-01-02Rollup test fixes and rebase conflictsAlex Crichton-1/+1
2015-01-02rollup merge of #20416: nikomatsakis/coherenceAlex Crichton-4/+7
Conflicts: src/test/run-pass/issue-15734.rs src/test/run-pass/issue-3743.rs
2015-01-02Disable the JSON doctests because they don't pass the new coherenceNiko Matsakis-3/+6
rules and cannot be updated until the libraries are synced, nor can they opt in to the old semantics.
2015-01-02Fix orphan checking (cc #19470). (This is not a complete fix of #19470 ↵Niko Matsakis-1/+1
because of the backwards compatibility feature gate.) This is a [breaking-change]. The new rules require that, for an impl of a trait defined in some other crate, two conditions must hold: 1. Some type must be local. 2. Every type parameter must appear "under" some local type. Here are some examples that are legal: ```rust struct MyStruct<T> { ... } // Here `T` appears "under' `MyStruct`. impl<T> Clone for MyStruct<T> { } // Here `T` appears "under' `MyStruct` as well. Note that it also appears // elsewhere. impl<T> Iterator<T> for MyStruct<T> { } ``` Here is an illegal example: ```rust // Here `U` does not appear "under" `MyStruct` or any other local type. // We call `U` "uncovered". impl<T,U> Iterator<U> for MyStruct<T> { } ``` There are a couple of ways to rewrite this last example so that it is legal: 1. In some cases, the uncovered type parameter (here, `U`) should be converted into an associated type. This is however a non-local change that requires access to the original trait. Also, associated types are not fully baked. 2. Add `U` as a type parameter of `MyStruct`: ```rust struct MyStruct<T,U> { ... } impl<T,U> Iterator<U> for MyStruct<T,U> { } ``` 3. Create a newtype wrapper for `U` ```rust impl<T,U> Iterator<Wrapper<U>> for MyStruct<T,U> { } ``` Because associated types are not fully baked, which in the case of the `Hash` trait makes adhering to this rule impossible, you can temporarily disable this rule in your crate by using `#![feature(old_orphan_check)]`. Note that the `old_orphan_check` feature will be removed before 1.0 is released.
2015-01-01std: Enforce Unicode in fmt::WriterAlex Crichton-134/+147
This commit is an implementation of [RFC 526][rfc] which is a change to alter the definition of the old `fmt::FormatWriter`. The new trait, renamed to `Writer`, now only exposes one method `write_str` in order to guarantee that all implementations of the formatting traits can only produce valid Unicode. [rfc]: https://github.com/rust-lang/rfcs/blob/master/text/0526-fmt-text-writer.md One of the primary improvements of this patch is the performance of the `.to_string()` method by avoiding an almost-always redundant UTF-8 check. This is a breaking change due to the renaming of the trait as well as the loss of the `write` method, but migration paths should be relatively easy: * All usage of `write` should move to `write_str`. If truly binary data was being written in an implementation of `Show`, then it will need to use a different trait or an altogether different code path. * All usage of `write!` should continue to work as-is with no modifications. * All usage of `Show` where implementations just delegate to another should continue to work as-is. [breaking-change] Closes #20352
2015-01-02More falloutNick Cameron-1/+1
2015-01-02Fallout - change array syntax to use `;`Nick Cameron-3/+3
2014-12-29rollup merge of #20279: dgiagio/libserialize_deprecated_fix1Alex Crichton-5/+5
Fixes #20278
2014-12-29rollup merge of #20264: nagisa/threadrngAlex Crichton-2/+2
Since runtime is removed, rust has no tasks anymore and everything is moving from being task-* to thread-*. Let’s rename TaskRng as well! This is a breaking change. If a breaking change for consistency is not desired, feel free to close.
2014-12-29rollup merge of #20182: brianloveswords/patch-2Alex Crichton-1/+1
Treemap should be BTreeMap
2014-12-28Fix deprecation warnings on libserialize testsDiego Giagio-5/+5
2014-12-28Rename TaskRng to ThreadRngSimonas Kazlauskas-2/+2
Since runtime is removed, rust has no tasks anymore and everything is moving from being task-* to thread-*. Let’s rename TaskRng as well! * Rename TaskRng to ThreadRng * Rename task_rng to thread_rng [breaking-change]
2014-12-23Update json.rsBrian J Brennan-1/+1
Treemap should be BTreeMap
2014-12-23Rename and namespace `FPCategory`Tobias Bucher-4/+5
Rename `FPCategory` to `FpCategory` and `Fp* to `*` in order to adhere to the naming convention This is a [breaking-change]. Existing code like this: ``` use std::num::{FPCategory, FPNaN}; ``` should be adjusted to this: ``` use std::num::FpCategory as Fp ``` In the following code you can use the constants `Fp::Nan`, `Fp::Normal`, etc.
2014-12-22rollup merge of #20089: rolftimmermans/json-control-chars-escapeAlex Crichton-3/+34
Conflicts: src/libserialize/json.rs
2014-12-22rollup merge of #20033: alexcrichton/deprecate-serialiseAlex Crichton-14/+18
This commit completes the deprecation story for the in-tree serialization library. The compiler will now emit a warning whenever it encounters `deriving(Encodable)` or `deriving(Decodable)`, and the library itself is now marked `#[unstable]` for when feature staging is enabled. All users of serialization can migrate to the `rustc-serialize` crate on crates.io which provides the exact same interface as the libserialize library in-tree. The new deriving modes are named `RustcEncodable` and `RustcDecodable` and require `extern crate "rustc-serialize" as rustc_serialize` at the crate root in order to expand correctly. To migrate all crates, add the following to your `Cargo.toml`: [dependencies] rustc-serialize = "0.1.1" And then add the following to your crate root: extern crate "rustc-serialize" as rustc_serialize; Finally, rename `Encodable` and `Decodable` deriving modes to `RustcEncodable` and `RustcDecodable`. [breaking-change]
2014-12-22Remove unnecessary deref().Rolf Timmermans-1/+1
2014-12-22Avoid allocations.Rolf Timmermans-8/+35
2014-12-22Escape control characters in JSON output.Rolf Timmermans-8/+12
2014-12-22serialize: Fully deprecate the libraryAlex Crichton-14/+18
This commit completes the deprecation story for the in-tree serialization library. The compiler will now emit a warning whenever it encounters `deriving(Encodable)` or `deriving(Decodable)`, and the library itself is now marked `#[unstable]` for when feature staging is enabled. All users of serialization can migrate to the `rustc-serialize` crate on crates.io which provides the exact same interface as the libserialize library in-tree. The new deriving modes are named `RustcEncodable` and `RustcDecodable` and require `extern crate "rustc-serialize" as rustc_serialize` at the crate root in order to expand correctly. To migrate all crates, add the following to your `Cargo.toml`: [dependencies] rustc-serialize = "0.1.1" And then add the following to your crate root: extern crate "rustc-serialize" as rustc_serialize; Finally, rename `Encodable` and `Decodable` deriving modes to `RustcEncodable` and `RustcDecodable`. [breaking-change]
2014-12-21Fallout of std::str stabilizationAlex Crichton-98/+99
2014-12-21rollup merge of #19980: erickt/cleanup-serializeAlex Crichton-34/+9
This brings over some changes from [rustc-serialize](https://github.com/rust-lang/rustc-serialize). It makes sense to keep the two in sync until we finally remove libserialize, just to make sure they don't diverge from each other.
2014-12-21rollup merge of #19974: vhbit/json-unicode-literalsAlex Crichton-3/+3
2014-12-19libserialize: use `#[deriving(Copy)]`Jorge Aparicio-16/+7
2014-12-18enumset falloutAlexis Beingessner-62/+6
2014-12-18s/Tree/BTreeAlexis Beingessner-24/+24
2014-12-18librustc: Always parse `macro!()`/`macro![]` as expressions if notPatrick Walton-26/+28
followed by a semicolon. This allows code like `vec![1i, 2, 3].len();` to work. This breaks code that uses macros as statements without putting semicolons after them, such as: fn main() { ... assert!(a == b) assert!(c == d) println(...); } It also breaks code that uses macros as items without semicolons: local_data_key!(foo) fn main() { println("hello world") } Add semicolons to fix this code. Those two examples can be fixed as follows: fn main() { ... assert!(a == b); assert!(c == d); println(...); } local_data_key!(foo); fn main() { println("hello world") } RFC #378. Closes #18635. [breaking-change]
2014-12-18serialize: silence some warningsErick Tryzelaar-9/+9
2014-12-18serialize: keep libserialize in sync with rustc-serialize to simplify mergingErick Tryzelaar-28/+3
2014-12-18Fixed deprecation warnings on Unicode literalsValerii Hiora-3/+3
2014-12-17rollup merge of #19887: alexcrichton/serialize-fn-mutAlex Crichton-8/+9
Relax some of the bounds on the decoder methods back to FnMut to help accomodate some more flavorful variants of decoders which may need to run the closure more than once when it, for example, attempts to find the first successful enum to decode.
2014-12-17rollup merge of #19764: lifthrasiir/that-stray-nulAlex Crichton-26/+28
Fixes #19719.
2014-12-15serialize: Change some FnOnce bounds to FnMutAlex Crichton-8/+9
Relax some of the bounds on the decoder methods back to FnMut to help accomodate some more flavorful variants of decoders which may need to run the closure more than once when it, for example, attempts to find the first successful enum to decode. This a breaking change due to the bounds for the trait switching, and clients will need to update from `FnOnce` to `FnMut` as well as likely making the local function binding mutable in order to call the function. [breaking-change]
2014-12-15Remove all shadowed lifetimes.Niko Matsakis-3/+3
2014-12-13libserialize: use unboxed closuresJorge Aparicio-1/+1
2014-12-13libserialize: use unboxed closuresJorge Aparicio-261/+304
2014-12-12serialize: Avoid stray nul characters when auto-serializing char.Kang Seonghoon-26/+28
Fixes #19719.
2014-12-11Register new snapshotsAlex Crichton-7/+7
2014-12-09serialize: base64: remove some .as_bytes() from the testsArcterus-6/+6
2014-12-09serialize: base64: improve newline handling speedArcterus-15/+13
2014-12-09serialize: base64: allow LF in addition to CRLF and optimize slightlyArcterus-30/+64
It is useful to have configurable newlines in base64 as the standard leaves that for the implementation to decide. GNU `base64` apparently uses LF, which meant in `uutils` we had to manually convert the CRLF to LF. This made the program very slow for large inputs. [breaking-change]
2014-12-09auto merge of #19249 : barosl/rust/json-type-safety, r=alexcrichtonbors-169/+169
This pull request tries to improve type safety of `serialize::json::Encoder`. Looking at #18319, I decided to test some JSON implementations in other languages. The results are as follows: * Encoding to JSON | Language | 111111111111111111 | 1.0 | | --- | --- | --- | | JavaScript™ | "111111111111111100" | "1" | | Python | "111111111111111111" | **"1.0"** | | Go | "111111111111111111" | "1" | | Haskell | "111111111111111111" | "1" | | Rust | **"111111111111111104"** | "1" | * Decoding from JSON | Language | "1" | "1.0" | "1.6" | | --- | --- | --- | --- | | JavaScript™ | 1 (Number) | 1 (Number) | 1.6 (Number) | | Python | 1 (int) | 1.0 (float) | 1.6 (float) | | Go | **1 (float64)** | 1 (float64) | 1.6 (float64) | | Go (expecting `int`) | 1 (int) | **error** | error | | Haskell (with `:: Int`) | 1 (Int) | 1 (Int) | **2 (Int)** | | Haskell (with `:: Double`) | 1.0 (Double) | 1.0 (Double) | 1.6 (Double) | | Rust (with `::<int>`) | 1 (int) | 1 (Int) | **1 (Int)** | | Rust (with `::<f64>`) | 1 (f64) | 1 (f64) | 1.6 (f64) | * The tests on Haskell were done using the [json](http://hackage.haskell.org/package/json) package. * The error message printed by Go was: `cannot unmarshal number 1.0 into Go value of type int` As you see, there is no uniform behavior. Every implementation follows its own principle. So I think it is reasonable to find a desirable set of behaviors for Rust. Firstly, every implementation except the one for JavaScript is capable of handling `i64` values. It is even practical, because [Twitter API uses an i64 number to represent a tweet ID](https://dev.twitter.com/overview/api/twitter-ids-json-and-snowflake), although it is recommended to use the string version of the ID. Secondly, looking into the Go's behavior, implicit type conversion is not allowed in their decoder. If the user expects an integer value to follow, decoding a float value will raise an error. This behavior is desirable in Rust, because we are pleased to follow the principles of strong typing. Thirdly, Python's JSON module forces a decimal point to be printed even if the fractional part does not exist. This eases the distinction of a float value from an integer value in JSON, because by the spec there is only one type to represent numbers, `Number`. So, I suggest the following three breaking changes: 1. Remove float preprocessing in serialize::json::Encoder `serialize::json::Encoder` currently uses `f64` to emit any integral type. This is possibly due to the behavior of JavaScript, which uses `f64` to represent any numeric value. This leads to a problem that only the integers in the range of [-2^53+1, 2^53-1] can be encoded. Therefore, `i64` and `u64` cannot be used reliably in the current implementation. [RFC 7159](http://tools.ietf.org/html/rfc7159) suggests that good interoperability can be achieved if the range is respected by implementations. However, it also says that implementations are allowed to set the range of number accepted. And it seems that the JSON encoders outside of the JavaScript world usually make use of `i64` values. This commit removes the float preprocessing done in the `emit_*` methods. It also increases performance, because transforming `f64` into String costs more than that of an integral type. Fixes #18319 2. Do not coerce to integer when decoding a float value When an integral value is expected by the user but a fractional value is found, the current implementation uses `std::num::cast()` to coerce to an integer type, losing the fractional part. This behavior is not desirable because the number loses precision without notice. This commit makes it raise `ExpectedError` when such a situation arises. 3. Always use a decimal point when emitting a float value JSON doesn't distinguish between integer and float. They are just numbers. Also, in the current implementation, a fractional number without the fractional part is encoded without a decimal point. Thereforce, when the value is decoded, it is first rendered as `Json`, either `I64` or `U64`. This reduces type safety, because while the original intention was to cast the value to float, it can also be casted to integer. As a workaround of this problem, this commit makes the encoder always emit a decimal point even if it is not necessary. If the fractional part of a float number is zero, ".0" is padded to the end of the result.
2014-12-08librustc: Make `Copy` opt-in.Niko Matsakis-0/+12
This change makes the compiler no longer infer whether types (structures and enumerations) implement the `Copy` trait (and thus are implicitly copyable). Rather, you must implement `Copy` yourself via `impl Copy for MyType {}`. A new warning has been added, `missing_copy_implementations`, to warn you if a non-generic public type has been added that could have implemented `Copy` but didn't. For convenience, you may *temporarily* opt out of this behavior by using `#![feature(opt_out_copy)]`. Note though that this feature gate will never be accepted and will be removed by the time that 1.0 is released, so you should transition your code away from using it. This breaks code like: #[deriving(Show)] struct Point2D { x: int, y: int, } fn main() { let mypoint = Point2D { x: 1, y: 1, }; let otherpoint = mypoint; println!("{}{}", mypoint, otherpoint); } Change this code to: #[deriving(Show)] struct Point2D { x: int, y: int, } impl Copy for Point2D {} fn main() { let mypoint = Point2D { x: 1, y: 1, }; let otherpoint = mypoint; println!("{}{}", mypoint, otherpoint); } This is the backwards-incompatible part of #13231. Part of RFC #3. [breaking-change]
2014-12-08libserialize: Prefer into_string() to to_string() wherever possibleBarosl Lee-85/+85
Except for the example code!
2014-12-08libserialize: Code cleanupBarosl Lee-69/+65
2014-12-08libserialize: Always use a decimal point when emitting a float valueBarosl Lee-3/+4
JSON doesn't distinguish between integer and float. They are just numbers. Also, in the current implementation, a fractional number without the fractional part is encoded without a decimal point. Thereforce, when the value is decoded, it is first rendered as Json, either I64 or U64. This reduces type safety, because while the original intention was to cast the value to float, it can also be casted to integer. As a workaround of this problem, this commit makes the encoder always emit a decimal point even if it is not necessary. If the fractional part of a float number is zero, ".0" is padded to the end of the result. [breaking-change]
2014-12-08libserialize: Do not coerce to integer when decoding a float valueBarosl Lee-4/+4
When an integral value is expected by the user but a fractional value is found, the current implementation uses std::num::cast() to coerce to an integer type, losing the fractional part. This behavior is not desirable because the number loses precision without notice. This commit makes it raise ExpectedError when such a situation arises. [breaking-change]
2014-12-08libserialize: Remove float preprocessing in serialize::json::EncoderBarosl Lee-21/+24
serialize::json::Encoder currently uses f64 to emit any integral type. This is possibly due to the behavior of JavaScript, which uses f64 to represent any numeric value. This leads to a problem that only the integers in the range of [-2^53+1, 2^53-1] can be encoded. Therefore, i64 and u64 cannot be used reliably in the current implementation. RFC 7159 suggests that good interoperability can be achieved if the range is respected by implementations. However, it also says that implementations are allowed to set the range of number accepted. And it seems that the JSON encoders outside of the JavaScript world usually make use of i64 values. This commit removes the float preprocessing done in the emit_* methods. It also increases performance, because transforming f64 into String costs more than that of an integral type. Fixes #18319 [breaking-change]
2014-12-06libserialize: remove unnecessary `to_string()` callsJorge Aparicio-63/+63