Commit graph

366 commits

Author SHA1 Message Date
John-John Tedro 0616d3562c Make spanned module private and hide internals 2018-05-09 21:54:22 +02:00
John-John Tedro 407845d620 Fix incorrectly reported spans for Datetime 2018-05-07 05:36:41 +02:00
John-John Tedro 8a9ae07de5 Use BorrowedStrDeserializer instead of generated key deserializers 2018-05-07 04:57:16 +02:00
John-John Tedro 09c8957ae7 Adjust spans for more complex types 2018-05-07 04:28:00 +02:00
John-John Tedro 6b919f8833 Use custom struct/field naming to deserialize spans 2018-05-07 04:28:00 +02:00
David Tolnay 6db43965f9 Proof of concept: reporting span information to a Spanned<T> type 2018-05-06 11:06:00 +02:00
John-John Tedro 6d7c89169b Make Tokenizer emit spans 2018-05-01 13:53:52 +02:00
Kornel 6cf0d5de33 Replace try!() with ? 2018-04-16 02:12:39 +01:00
David Tolnay eab7d806e9 A toml macro 2017-11-12 23:46:34 -08:00
Alex Crichton a3f02da0c3 Merge pull request #213 from behnam/doc
[value] Fix some method docs
2017-09-15 09:07:55 -05:00
Behnam Esfahbod ✅ b7af13e689 [value] Fix some method docs 2017-09-14 22:37:51 -07:00
Alex Crichton dd4c5131eb Fix a number of compile warnings 2017-08-28 07:40:48 -07:00
Garrett Berg d386be1a49 add pretty_string_literal to be able to disable literal strings 2017-08-13 17:19:02 -06:00
Garrett Berg 76f11f2033 add spaces between array items and test for them 2017-08-13 15:31:09 -06:00
Alex Crichton ea0c2296e6 Merge pull request #204 from vitiral/rc_settings
reference count settings to bump performance a bit
2017-07-31 10:58:48 -05:00
Garrett Berg 9443fbf01f back out doc changes for now 2017-07-30 10:19:32 -06:00
Garrett Berg eb69fee5ff doc fixes 2017-07-30 10:18:00 -06:00
Garrett Berg 003a65fc9f reference count settings to bump performance a bit 2017-07-29 00:41:35 -06:00
Garrett Berg 54a4833bc1 add """ for non-literals with newlines, clean up logic and add tests 2017-07-28 09:25:53 -06:00
Garrett Berg dabe477d64 make single lines also pretty 2017-07-28 07:14:37 -06:00
Garrett Berg 83be829f0b fix bugs with pretty 2017-07-27 22:01:36 -06:00
Garrett Berg 61ff3c295c close #199: add header information for empty structs
- also add test which fails without this change
- also add a few helpful unit tests to table
2017-07-27 07:03:52 -06:00
Garrett Berg 203b4d43c2 fix Serializer::pretty_array(false) 2017-07-24 09:46:24 -06:00
Garrett Berg fba6170b95 use ignore rather than no_run for toml blocks 2017-07-24 09:18:47 -06:00
Garrett Berg ec82e695ba fix docs and add 2017-07-22 15:11:23 -06:00
Garrett Berg 973e4cc8c7 fix " 2017-07-21 12:03:42 -06:00
Garrett Berg 1e060c55d6 use builder pattern 2017-07-20 12:47:51 -06:00
Garrett Berg 3ec47e6758 pretty arrays 2017-07-09 15:20:29 -06:00
Garrett Berg 27757113ec array doesn't break anything... 2017-07-09 15:10:36 -06:00
Garrett Berg fe894fee6c add pretty sting serialization 2017-07-09 14:58:48 -06:00
Garrett Berg 36a4ebd3bf add Settings struct 2017-07-09 14:38:48 -06:00
Alex Crichton 66bbdb36a6 One more case of handling newtype structs 2017-07-06 11:43:36 -07:00
Alex Crichton 7a8c535c5a Support deserializing newtypes
Closes #196
2017-07-06 07:34:45 -07:00
debris eb138b12b9 updated toml version in the docs 0.4.2 2017-06-23 23:16:25 +02:00
Sergio Benitez 7f9e594e47 Use 'into()' to convert numerical values safely 2017-06-19 17:49:55 -07:00
Sergio Benitez f936fcfb13 Add exhaustive From<T> impls for Value 2017-06-18 03:06:19 -07:00
Pit Kleyersburg e89345af42 Implement IntoDeserializer for Value 2017-06-11 17:44:41 +02:00
Alan Du 5d36195f2d Store fractional seconds as a u32 instead of a f64
Drops precision down to the nanoseconds
2017-06-01 23:22:35 +01:00
Alan Du ce7b96c47b Add toml::ser::Error::KeyNewline back in
Avoid a breaking change
2017-06-01 22:47:24 +01:00
Alan Du bad367cab0 Allow serializing keys with \n in them
Use special quoted form

Closes https://github.com/alexcrichton/toml-rs/issues/185
2017-06-01 20:59:26 +01:00
Alan Du 4e246b2142 Truncate fractional seconds to picoseconds
Close https://github.com/alexcrichton/toml-rs/issues/186
2017-06-01 20:57:06 +01:00
Alan Du d8cc119799 Close #180 2017-06-01 12:42:16 +01:00
Alex Crichton 9a8c5d8e96 Merge pull request #183 from alanhdu/invalid_number
Better invalid number handling
2017-05-30 19:37:44 -05:00
Alan Du 87f51b38d1 Error when trying to serialize invalid float 2017-05-31 00:30:58 +01:00
Alan Du 90040b34b6 Error when parsing numbers outside of f64's range 2017-05-31 00:30:55 +01:00
Alan Du 90bdb7e96d Encode control characters with hex not decimal
Fix https://github.com/alexcrichton/toml-rs/issues/178
2017-05-30 23:55:09 +01:00
Alan Du d375f4d63a Store fraction of seconds in times unconditionally
This way, times without fractional seconds  will be compare equal to
times with 0 fractional seconds if all else is equal. For example,
    06:00:00 == 06:00:00.0

Closes https://github.com/alexcrichton/toml-rs/issues/179
2017-05-30 23:50:58 +01:00
Alex Crichton 38c17e6dca Merge pull request #172 from rap2hpoutre/patch-1
add example for from_str
2017-05-10 13:19:47 -05:00
Raphaël Huchet d5ffc6cc60 add example for to_string 2017-05-10 17:39:19 +02:00
Raphaël Huchet 9158482ed9 Update de.rs 2017-05-10 17:17:58 +02:00
Raphaël Huchet 0d3b3e3a36 add example for from_str 2017-05-10 16:49:35 +02:00
Oliver Schneider 80ed3e7a7b Document that line/col indices are 0 based 2017-05-09 17:08:26 +02:00
Oliver Schneider 26d39b3a15 Allow extracting the location of the error 2017-05-09 11:22:18 +02:00
Alex Crichton bac92cdfad Update doc urls to 0.4
Closes #168
2017-05-02 09:20:11 -07:00
Alex Crichton 137157f445 Merge pull request #165 from Keats/master
Allow to deserialize/serialize into enums
2017-04-28 15:01:08 -05:00
Vincent Prouillet a6f22570ae Address comment and make test pass 2017-04-28 13:00:37 +09:00
Vincent Prouillet c675b4f259 Deserialize enum in Value 2017-04-25 13:57:35 +09:00
Vincent Prouillet 36f33ff3b3 Remove everything other than enum variant code 2017-04-25 12:06:04 +09:00
Dzmitry Malyshau 962506e5d6 Fixed the serde dependency in the documentation 2017-04-24 10:05:55 -04:00
Vincent Prouillet 7cb357c168 Allow to deserialize/serialize into enums
Close #164
2017-04-24 22:13:38 +09:00
Alex Crichton dc5ff1ef90 Support serde 1.0.0 2017-04-20 10:16:00 -07:00
Daniel Lockyer 469e9f6bd2 Remove lifetimes 2017-04-12 09:29:00 +01:00
Daniel Lockyer cecb0b58a7 Stop taking references when not needed 2017-04-12 09:29:00 +01:00
Daniel Lockyer 3034a7cf52 Simplify if-statements 2017-04-12 09:28:56 +01:00
Daniel Lockyer 50714395c2 Switch from comparison to is_empty() 2017-04-12 09:24:16 +01:00
Daniel Lockyer de940a3373 Remove unneeded return statements 2017-04-12 09:24:16 +01:00
Alex Crichton a87d005cc1 Merge pull request #161 from colin-kiegel/crate-polish
Crate polish
2017-04-05 16:50:51 -07:00
Matthias Endler 6f2f475b88 Replace unwrap with expect in public methods 2017-04-05 21:56:18 +02:00
Colin Kiegel 22168aa100 group mod statements consistently 2017-04-05 21:30:32 +02:00
Colin Kiegel 36b9b268ba remove deadcode (unused since e256931e9b) 2017-04-05 21:24:11 +02:00
Colin Kiegel 9d761f5614 doc - group link definitions 2017-04-05 20:51:36 +02:00
Alex Crichton 5152f3aca0 Fix backcompat with array definitions 2017-03-31 18:45:00 -07:00
Alex Crichton b6178aed2a Relax assertions in substr_offset slightly
Closes #152
2017-02-21 20:27:43 -08:00
Alex Crichton c680668d22 Merge pull request #151 from EPashkin/fix_table_values_sorting
Fixed sorting of table values
2017-02-21 09:31:19 -06:00
Alex Crichton edf22b74a1 Add support for serialize_bytes
Just serialize as a list of numbers.

Closes #150
2017-02-21 06:21:00 -08:00
Evgenii Pashkin ded040ae9e Fixed sorting of table values 2017-02-19 18:15:58 +03:00
Alex Crichton 2fd12e72d8 Fix displaying empty arrays
Closes #145
2017-02-11 09:13:33 -08:00
Alex Crichton 67fb9f1953 Add a serialization helper to put tables last
This should help serializing maps where it's unknown up front whether the tables
and/or values come first.

Closes #142
2017-02-10 15:29:36 -08:00
Jonas mg b5ec7d2c33 Update ser.rs 2017-02-10 14:37:47 +00:00
Jake Goulding 90630d66fb Remove newline that causes strange rendering 2017-02-09 10:41:58 -05:00
Jake Goulding f49d0b3246 Tighten up the crate-level docs 2017-02-09 10:12:23 -05:00
Jake Goulding 22c3df7625 Grammar on Value doc strings 2017-02-09 10:09:20 -05:00
Alex Crichton d02c02d995 Implement Deserializer::set_require_newline_after_table 2017-02-08 21:36:38 -08:00
Alex Crichton e256931e9b Rewrite crate with serde support from ground up
This commit completely rewrites this crate from the ground up,
supporting serde at the lowest levels as I believe serde support was
intended to do. This is a major change from the previous versions of
this crate, with a summary of changes being:

* Serialization directly to TOML is now supported without going through
  a `Value` first.

* Deserialization directly from TOML is now supported without going
  through a `Value`. Note that due to the TOML format some values still
  are buffered in intermediate memory, but overall this should be at a
  minimum now.

* The API of `Value` was overhauled to match the API of
  `serde_json::Value`. The changes here were to:

  * Add `is_*` accessors
  * Add `get` and `get_mut` for one-field lookups.
  * Implement panicking lookups through `Index`

  The old `index` methods are now gone in favor of `get` and `Index`
  implementations.

* A `Datetime` type has been added to represent a TOML datetime in a
  first-class fashion. Currently this type provides no accessors other
  than a `Display` implementation, but the idea is that this will grow
  support over time for decomposing the date.

* Support for the `rustc-serialize` crate has been dropped, that'll stay
  on the 0.2 and 0.1 release trains.

* This crate no longer supports the detection of unused fields, for that though
  you can use the `serde_ignored` crate on crates.io
2017-02-08 21:21:18 -08:00
Alex Crichton 0dc5347946 Clarify that serde is supported
Closes #122
2017-01-09 17:37:05 -08:00
Alex Crichton 5907e0a7d0 Return encoding errors for NaN and infinite
TOML can't actually represent them, so we should bail out.

Closes #125
2016-12-30 17:40:40 -08:00
Alex Crichton f66b9913f9 Escape control characters when encoding strings
Closes #126
2016-12-30 17:34:11 -08:00
nabijaczleweli 594b845b5a Don't space out the first table or array if not needed
Closes #110
2016-09-06 09:01:06 +02:00
Vinzent Steinberg 2299cb3744 Fix a typo 2016-08-16 23:41:53 +02:00
Alex Crichton 4ee9cb72e6 Touch up the encoder/decoder a bit
* Whitespace things
* Don't make `State` public
* Remove `#[cfg]` annotations
2016-07-29 10:23:06 -07:00
David Tolnay c17b75f834 Restore defaulted Deserializer methods 2016-07-29 00:55:52 -07:00
David Tolnay 242b8038a1 Cfg off functions only needed for rustc-serialize or serde 2016-07-28 11:09:50 -07:00
David Tolnay 492690669e Update to serde 0.8.0 2016-07-28 11:09:40 -07:00
Oliver Schneider c7d96b191e next iteration 2016-07-15 16:24:26 +02:00
Oliver Schneider 183646b118 adjust for seq/map ser revamp 2016-07-14 15:28:51 +02:00
Alex Crichton fb8050d2d5 Merge pull request #101 from leodasvacas/clippy-run
Clippy run and implement Default for State and Enconder
2016-06-05 07:46:17 +02:00
leonardo.yvens e8097b14f1 Clippy run 2016-06-03 23:19:15 -03:00
Alex Crichton 7363dbe7f5 Merge pull request #103 from MarkSwanson/lookup-lifetime-enhancement
lookup() and lookup_mut() lifetime enhancements.
2016-06-01 12:36:30 -07:00
Alex Crichton 6f43fc3b29 Fix serde tests on nightly 2016-05-31 10:41:47 -07:00
Mark Swanson 3639e62a3b Rely on lifetime elision. 2016-05-31 10:20:43 -04:00
Mark Swanson 010e34f637 lookup() and lookup_mut() lifetime enhancements.
Rationale:

- The path has nothing to do with the result.
- The path has no need to live as long as the Value/self.
- In some cases it can be hard to actually build a path that meets
  the same lifetime requirements as the Value or String slice result.
2016-05-30 16:09:40 -04:00
Alex Crichton 44fc9d9f37 Require newlines to be present after keys
Closes #100
2016-05-22 23:30:43 -07:00
James Sanderson dd7e31ea53 Refactor checking for EOF into method 2016-05-19 01:12:58 +01:00
James Sanderson 112adaaa3f Accept empty table on last line 2016-05-19 01:09:33 +01:00
James Sanderson 6450da87ba Failing test for empty table on last line 2016-05-19 00:54:54 +01:00
Alex Crichton b9280519cc Fix accepting comments after table definitions 2016-05-16 10:17:51 -07:00
Alex Crichton c777001598 Accept fractional seconds and timezones in datetime parsing
Closes #96
2016-05-12 14:07:34 -07:00
Alex Crichton 1ed6801137 Add option to enable old behavior
Cargo will use this in the interim.
2016-05-12 11:28:32 -07:00
James Sanderson 848227c605 Require a newline after table definition 2016-04-17 22:51:43 +01:00
Tae-il Lim 6426b02d3d Use different method to ensure unicode escape code is ASCII of expected length 2016-04-05 11:13:36 +09:00
Bourgond Aries 644dc88c04 Add a bunch of negative and positive tests 2016-03-28 06:35:39 +02:00
Bourgond Aries 33c49d0357 Leverage fn array_index to fn integer 2016-03-28 06:24:25 +02:00
Bourgond Aries 568dd2ef4b Fix the indentation to be consistent with the repository 2016-03-27 21:19:03 +02:00
Bourgond Aries 442f663c2d Add advanced lookup for table names 2016-03-27 20:55:49 +02:00
Bourgond Aries 770052a9a7 Add a test for lookup_mut_advanced 2016-03-27 20:50:25 +02:00
Bourgond Aries 0e3e0654ba Implement advanced key lookup for lookup_mut 2016-03-27 20:48:23 +02:00
Bourgond Aries 3517215eab Implement a more advanced algorithm for lookup
The new algorithm allows the explicit usage of "" and '' to denote key
names. This is useful for accessing tables or keys that are named in a
non-conventional manner.
2016-03-27 20:46:19 +02:00
Bourgond Aries b171205c57 Add a test to see if the table's contents have changed 2016-03-25 17:43:32 +01:00
Bourgond Aries 32969ca891 Implement the non-recursive lookup_mut
Also include some tests simply by copying and modifying
the other tests for lookup.
2016-03-25 17:33:46 +01:00
Bourgond Aries 9b1dc843fc Add lookup_mut method for mutable access
Mutable access may sometimes be desired in order to change values
in the toml table. This can be used for dynamic configurations which
will be easy to modify and store.

lookup_mut requires a recursive method due to the borrow checker
not allowing to have more than one mutable reference in the same
scope.
2016-03-24 14:18:00 +01:00
Alex Crichton 511c235d7d Fix last tests 2016-03-11 09:20:32 -08:00
Alex Crichton 3345fea319 Fix an error message test, simlify some serde code 2016-03-11 01:32:16 -08:00
Alex Crichton d02e622330 WIP 2016-03-07 23:48:01 -08:00
Alex Crichton 6b0a1362a1 Support literal strings in table names
Closes #85
2016-01-24 10:50:39 -08:00
Corey Farwell 7be39d725d Address issues found by rust-clippy 2016-01-21 08:38:09 -05:00
Jake Goulding 67107034fc Minor documentation grammar fix 2016-01-01 17:57:01 -05:00
Alex Crichton 39d77b6d79 When decoding maps, leave fields that weren't processed
Fixes an XXX
2015-12-18 16:29:07 -08:00
Cameron Silvestrini caa4615536 Fixed bug: floats always end up in Decoder.toml, even when they have
been successfully decoded.
2015-12-15 22:43:24 +11:00
osboxes.org dea8646b8b Allow BOM (Byte order mark) in toml 2015-10-07 11:35:49 +02:00
Guillaume Gomez db75e532e5 Add Clone derive on ParserError 2015-09-30 00:00:17 +02:00
Kerhong 547e202c15 Implement Value::lookup for empty path to return self 2015-09-25 19:26:47 +03:00
mseri dc0aa5f6c4 Fixed typo 2015-08-29 12:47:21 +01:00
Alex Gulyás 64ae43a386 Fix the arithmetic overflow in Parser::to_linecol
This also changes the calculated line and column numbers. Without this
patch, if an error occurs at the end of a line, the returned line and
column numbers will point at the start of the next line.

After this patch, the line and column numbers will correctly point at
the end of the line where the actual parse error happened.
2015-08-14 14:54:32 +02:00
Alex Crichton 7ec4821bd7 Touch up some style in the decoder 2015-08-13 09:47:40 -07:00
Erick Tryzelaar 85cd6f3e6e Rewrite the MapVisitor to add errors for a specific field 2015-08-13 08:25:56 -07:00
Erick Tryzelaar 8c33064c2c Override the numeric hints to not deserialize ints into floats, and vice versa 2015-08-13 08:25:56 -07:00
Erick Tryzelaar e5efc8801d Add a Deserialize::visit_enum that tries to deserialize into each variant
This could be more efficiently done if serde communicated the
number of arguments in each variant in this function.
2015-08-13 08:25:56 -07:00
Erick Tryzelaar b7b31bf9da Implement Serialize::visit_newtype_{struct,variant}
These functions allow a serializer to not wrap a newtyped value
inside of a tuple or struct.
2015-08-13 07:42:06 -07:00
Erick Tryzelaar bbc167cde9 Get serde feature compiling again 2015-08-12 23:01:49 -07:00
Erick Tryzelaar 4e0172a9a5 Merge remote-tracking branch 'remotes/origin/master' into serde 2015-08-12 22:15:58 -07:00
Alex Crichton b70f6e53b2 Don't need to qualify String 2015-08-11 09:18:52 -07:00
Ben Navetta 8a2282fecd it helps to actually build with serde enabled 2015-08-06 23:33:39 -04:00
Ben Navetta 00337d088e implement serde::Deserialize for Value 2015-08-06 23:30:08 -04:00
Alex Crichton 89332806c5 Improve the error message in failing enums 2015-06-23 17:45:48 -07:00
Alex Crichton 27a70d4024 Name the fields of the custom table AST 2015-06-08 00:04:30 -07:00
Alex Crichton 00baf76107 Add a few more tests for redefining tables 2015-06-07 23:58:45 -07:00
Alex Crichton 88461157f2 Clean up more style 2015-06-07 23:57:50 -07:00
Alex Crichton 68924534e2 Use deref coercions 2015-06-07 23:48:32 -07:00
Alex Crichton 6580b77a20 Re-structure control flow a bit + modernization 2015-06-07 23:47:22 -07:00
Andrzej Janik 8487b63c97 Rework fix for table redefinition to avoid breaking AST-compatiblity 2015-06-06 18:11:48 +02:00