diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cc24e39a..6cf00d57 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,6 +18,10 @@ jobs: - uses: actions-rs/cargo@v1 with: command: check + - uses: actions-rs/cargo@v1 + with: + command: check + args: --all-features test: name: Test @@ -38,6 +42,10 @@ jobs: - uses: actions-rs/cargo@v1 with: command: test + - uses: actions-rs/cargo@v1 + with: + command: test + args: --all-features fmt: name: Rustfmt @@ -69,5 +77,5 @@ jobs: - uses: actions-rs/cargo@v1 with: command: clippy - args: --all-targets -- -D warnings + args: --all-targets --all-features -- -D warnings diff --git a/Cargo.toml b/Cargo.toml index 6fae128a..ad298637 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,9 @@ repository = "https://github.com/ordian/toml_edit" documentation = "https://docs.rs/toml_edit" edition = "2018" +[package.metadata.docs.rs] +features = ["easy"] + [features] default = [] easy = ["serde"] diff --git a/src/easy/macros.rs b/src/easy/macros.rs index d0ba7833..af19b6b0 100644 --- a/src/easy/macros.rs +++ b/src/easy/macros.rs @@ -33,7 +33,7 @@ macro_rules! toml { ($($toml:tt)+) => {{ let table = $crate::easy::value::Table::new(); let mut root = $crate::easy::Value::Table(table); - $crate::easy::toml_internal!(@toplevel root [] $($toml)+); + $crate::toml_internal!(@toplevel root [] $($toml)+); root }}; } @@ -78,63 +78,63 @@ macro_rules! toml_internal { // Parse negative number `key = -value`. (@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = - $v:tt $($rest:tt)*) => { - $crate::easy::toml_internal!(@toplevel $root [$($path)*] $($($k)-+).+ = (-$v) $($rest)*); + $crate::toml_internal!(@toplevel $root [$($path)*] $($($k)-+).+ = (-$v) $($rest)*); }; // Parse positive number `key = +value`. (@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = + $v:tt $($rest:tt)*) => { - $crate::easy::toml_internal!(@toplevel $root [$($path)*] $($($k)-+).+ = ($v) $($rest)*); + $crate::toml_internal!(@toplevel $root [$($path)*] $($($k)-+).+ = ($v) $($rest)*); }; // Parse offset datetime `key = 1979-05-27T00:32:00.999999-07:00`. (@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt . $frac:tt - $tzh:tt : $tzm:tt $($rest:tt)*) => { - $crate::easy::toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $dhr : $min : $sec . $frac - $tzh : $tzm) $($rest)*); + $crate::toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $dhr : $min : $sec . $frac - $tzh : $tzm) $($rest)*); }; // Space instead of T. (@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt . $frac:tt - $tzh:tt : $tzm:tt $($rest:tt)*) => { - $crate::easy::toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $day T $hr : $min : $sec . $frac - $tzh : $tzm) $($rest)*); + $crate::toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $day T $hr : $min : $sec . $frac - $tzh : $tzm) $($rest)*); }; // Parse offset datetime `key = 1979-05-27T00:32:00-07:00`. (@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt - $tzh:tt : $tzm:tt $($rest:tt)*) => { - $crate::easy::toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $dhr : $min : $sec - $tzh : $tzm) $($rest)*); + $crate::toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $dhr : $min : $sec - $tzh : $tzm) $($rest)*); }; // Space instead of T. (@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt - $tzh:tt : $tzm:tt $($rest:tt)*) => { - $crate::easy::toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $day T $hr : $min : $sec - $tzh : $tzm) $($rest)*); + $crate::toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $day T $hr : $min : $sec - $tzh : $tzm) $($rest)*); }; // Parse local datetime `key = 1979-05-27T00:32:00.999999`. (@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt . $frac:tt $($rest:tt)*) => { - $crate::easy::toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $dhr : $min : $sec . $frac) $($rest)*); + $crate::toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $dhr : $min : $sec . $frac) $($rest)*); }; // Space instead of T. (@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt . $frac:tt $($rest:tt)*) => { - $crate::easy::toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $day T $hr : $min : $sec . $frac) $($rest)*); + $crate::toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $day T $hr : $min : $sec . $frac) $($rest)*); }; // Parse offset datetime `key = 1979-05-27T07:32:00Z` and local datetime `key = 1979-05-27T07:32:00`. (@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt $($rest:tt)*) => { - $crate::easy::toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $dhr : $min : $sec) $($rest)*); + $crate::toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $dhr : $min : $sec) $($rest)*); }; // Space instead of T. (@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt $($rest:tt)*) => { - $crate::easy::toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $day T $hr : $min : $sec) $($rest)*); + $crate::toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $day T $hr : $min : $sec) $($rest)*); }; // Parse local date `key = 1979-05-27`. (@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $yr:tt - $mo:tt - $day:tt $($rest:tt)*) => { - $crate::easy::toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $day) $($rest)*); + $crate::toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $day) $($rest)*); }; // Parse local time `key = 00:32:00.999999`. (@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $hr:tt : $min:tt : $sec:tt . $frac:tt $($rest:tt)*) => { - $crate::easy::toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($hr : $min : $sec . $frac) $($rest)*); + $crate::toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($hr : $min : $sec . $frac) $($rest)*); }; // Parse local time `key = 07:32:00`. (@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $hr:tt : $min:tt : $sec:tt $($rest:tt)*) => { - $crate::easy::toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($hr : $min : $sec) $($rest)*); + $crate::toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($hr : $min : $sec) $($rest)*); }; // Parse any other `key = value` including string, inline array, inline @@ -142,35 +142,35 @@ macro_rules! toml_internal { (@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $v:tt $($rest:tt)*) => {{ $crate::easy::macros::insert_toml( &mut $root, - &[$($path)* $(&concat!($("-", $crate::easy::toml_internal!(@path $k),)+)[1..], )+], - $crate::easy::toml_internal!(@value $v)); - $crate::easy::toml_internal!(@toplevel $root [$($path)*] $($rest)*); + &[$($path)* $(&concat!($("-", $crate::toml_internal!(@path $k),)+)[1..], )+], + $crate::toml_internal!(@value $v)); + $crate::toml_internal!(@toplevel $root [$($path)*] $($rest)*); }}; // Parse array header `[[bin]]`. (@toplevel $root:ident $oldpath:tt [[$($($path:tt)-+).+]] $($rest:tt)*) => { $crate::easy::macros::push_toml( &mut $root, - &[$(&concat!($("-", $crate::easy::toml_internal!(@path $path),)+)[1..],)+]); - $crate::easy::toml_internal!(@toplevel $root [$(&concat!($("-", $crate::easy::toml_internal!(@path $path),)+)[1..],)+] $($rest)*); + &[$(&concat!($("-", $crate::toml_internal!(@path $path),)+)[1..],)+]); + $crate::toml_internal!(@toplevel $root [$(&concat!($("-", $crate::toml_internal!(@path $path),)+)[1..],)+] $($rest)*); }; // Parse table header `[patch.crates-io]`. (@toplevel $root:ident $oldpath:tt [$($($path:tt)-+).+] $($rest:tt)*) => { $crate::easy::macros::insert_toml( &mut $root, - &[$(&concat!($("-", $crate::easy::toml_internal!(@path $path),)+)[1..],)+], + &[$(&concat!($("-", $crate::toml_internal!(@path $path),)+)[1..],)+], $crate::easy::Value::Table($crate::easy::value::Table::new())); - $crate::easy::toml_internal!(@toplevel $root [$(&concat!($("-", $crate::easy::toml_internal!(@path $path),)+)[1..],)+] $($rest)*); + $crate::toml_internal!(@toplevel $root [$(&concat!($("-", $crate::toml_internal!(@path $path),)+)[1..],)+] $($rest)*); }; // Parse datetime from string and insert into table. (@topleveldatetime $root:ident [$($path:tt)*] $($($k:tt)-+).+ = ($($datetime:tt)+) $($rest:tt)*) => { $crate::easy::macros::insert_toml( &mut $root, - &[$($path)* $(&concat!($("-", $crate::easy::toml_internal!(@path $k),)+)[1..], )+], + &[$($path)* $(&concat!($("-", $crate::toml_internal!(@path $k),)+)[1..], )+], $crate::easy::Value::Datetime(concat!($(stringify!($datetime)),+).parse().unwrap())); - $crate::easy::toml_internal!(@toplevel $root [$($path)*] $($rest)*); + $crate::toml_internal!(@toplevel $root [$($path)*] $($rest)*); }; // Turn a path segment into a string. @@ -187,14 +187,14 @@ macro_rules! toml_internal { // Construct a Value from an inline table. (@value { $($inline:tt)* }) => {{ let mut table = $crate::easy::Value::Table($crate::easy::value::Table::new()); - $crate::easy::toml_internal!(@trailingcomma (@table table) $($inline)*); + $crate::toml_internal!(@trailingcomma (@table table) $($inline)*); table }}; // Construct a Value from an inline array. (@value [ $($inline:tt)* ]) => {{ let mut array = $crate::easy::value::Array::new(); - $crate::easy::toml_internal!(@trailingcomma (@array array) $($inline)*); + $crate::toml_internal!(@trailingcomma (@array array) $($inline)*); $crate::easy::Value::Array(array) }}; @@ -234,81 +234,81 @@ macro_rules! toml_internal { // Parse negative number `key = -value`. (@table $root:ident $($($k:tt)-+).+ = - $v:tt , $($rest:tt)*) => { - $crate::easy::toml_internal!(@table $root $($($k)-+).+ = (-$v) , $($rest)*); + $crate::toml_internal!(@table $root $($($k)-+).+ = (-$v) , $($rest)*); }; // Parse positive number `key = +value`. (@table $root:ident $($($k:tt)-+).+ = + $v:tt , $($rest:tt)*) => { - $crate::easy::toml_internal!(@table $root $($($k)-+).+ = ($v) , $($rest)*); + $crate::toml_internal!(@table $root $($($k)-+).+ = ($v) , $($rest)*); }; // Parse offset datetime `key = 1979-05-27T00:32:00.999999-07:00`. (@table $root:ident $($($k:tt)-+).+ = $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt . $frac:tt - $tzh:tt : $tzm:tt , $($rest:tt)*) => { - $crate::easy::toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $dhr : $min : $sec . $frac - $tzh : $tzm) $($rest)*); + $crate::toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $dhr : $min : $sec . $frac - $tzh : $tzm) $($rest)*); }; // Space instead of T. (@table $root:ident $($($k:tt)-+).+ = $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt . $frac:tt - $tzh:tt : $tzm:tt , $($rest:tt)*) => { - $crate::easy::toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $day T $hr : $min : $sec . $frac - $tzh : $tzm) $($rest)*); + $crate::toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $day T $hr : $min : $sec . $frac - $tzh : $tzm) $($rest)*); }; // Parse offset datetime `key = 1979-05-27T00:32:00-07:00`. (@table $root:ident $($($k:tt)-+).+ = $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt - $tzh:tt : $tzm:tt , $($rest:tt)*) => { - $crate::easy::toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $dhr : $min : $sec - $tzh : $tzm) $($rest)*); + $crate::toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $dhr : $min : $sec - $tzh : $tzm) $($rest)*); }; // Space instead of T. (@table $root:ident $($($k:tt)-+).+ = $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt - $tzh:tt : $tzm:tt , $($rest:tt)*) => { - $crate::easy::toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $day T $hr : $min : $sec - $tzh : $tzm) $($rest)*); + $crate::toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $day T $hr : $min : $sec - $tzh : $tzm) $($rest)*); }; // Parse local datetime `key = 1979-05-27T00:32:00.999999`. (@table $root:ident $($($k:tt)-+).+ = $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt . $frac:tt , $($rest:tt)*) => { - $crate::easy::toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $dhr : $min : $sec . $frac) $($rest)*); + $crate::toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $dhr : $min : $sec . $frac) $($rest)*); }; // Space instead of T. (@table $root:ident $($($k:tt)-+).+ = $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt . $frac:tt , $($rest:tt)*) => { - $crate::easy::toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $day T $hr : $min : $sec . $frac) $($rest)*); + $crate::toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $day T $hr : $min : $sec . $frac) $($rest)*); }; // Parse offset datetime `key = 1979-05-27T07:32:00Z` and local datetime `key = 1979-05-27T07:32:00`. (@table $root:ident $($($k:tt)-+).+ = $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt , $($rest:tt)*) => { - $crate::easy::toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $dhr : $min : $sec) $($rest)*); + $crate::toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $dhr : $min : $sec) $($rest)*); }; // Space instead of T. (@table $root:ident $($($k:tt)-+).+ = $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt , $($rest:tt)*) => { - $crate::easy::toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $day T $hr : $min : $sec) $($rest)*); + $crate::toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $day T $hr : $min : $sec) $($rest)*); }; // Parse local date `key = 1979-05-27`. (@table $root:ident $($($k:tt)-+).+ = $yr:tt - $mo:tt - $day:tt , $($rest:tt)*) => { - $crate::easy::toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $day) $($rest)*); + $crate::toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $day) $($rest)*); }; // Parse local time `key = 00:32:00.999999`. (@table $root:ident $($($k:tt)-+).+ = $hr:tt : $min:tt : $sec:tt . $frac:tt , $($rest:tt)*) => { - $crate::easy::toml_internal!(@tabledatetime $root $($($k)-+).+ = ($hr : $min : $sec . $frac) $($rest)*); + $crate::toml_internal!(@tabledatetime $root $($($k)-+).+ = ($hr : $min : $sec . $frac) $($rest)*); }; // Parse local time `key = 07:32:00`. (@table $root:ident $($($k:tt)-+).+ = $hr:tt : $min:tt : $sec:tt , $($rest:tt)*) => { - $crate::easy::toml_internal!(@tabledatetime $root $($($k)-+).+ = ($hr : $min : $sec) $($rest)*); + $crate::toml_internal!(@tabledatetime $root $($($k)-+).+ = ($hr : $min : $sec) $($rest)*); }; // Parse any other type, probably string or boolean or number. (@table $root:ident $($($k:tt)-+).+ = $v:tt , $($rest:tt)*) => { $crate::easy::macros::insert_toml( &mut $root, - &[$(&concat!($("-", $crate::easy::toml_internal!(@path $k),)+)[1..], )+], - $crate::easy::toml_internal!(@value $v)); - $crate::easy::toml_internal!(@table $root $($rest)*); + &[$(&concat!($("-", $crate::toml_internal!(@path $k),)+)[1..], )+], + $crate::toml_internal!(@value $v)); + $crate::toml_internal!(@table $root $($rest)*); }; // Parse a Datetime from string and continue in @table state. (@tabledatetime $root:ident $($($k:tt)-+).+ = ($($datetime:tt)*) $($rest:tt)*) => { $crate::easy::macros::insert_toml( &mut $root, - &[$(&concat!($("-", $crate::easy::toml_internal!(@path $k),)+)[1..], )+], + &[$(&concat!($("-", $crate::toml_internal!(@path $k),)+)[1..], )+], $crate::easy::Value::Datetime(concat!($(stringify!($datetime)),+).parse().unwrap())); - $crate::easy::toml_internal!(@table $root $($rest)*); + $crate::toml_internal!(@table $root $($rest)*); }; // Base case of inline array. @@ -316,95 +316,95 @@ macro_rules! toml_internal { // Parse negative number `-value`. (@array $root:ident - $v:tt , $($rest:tt)*) => { - $crate::easy::toml_internal!(@array $root (-$v) , $($rest)*); + $crate::toml_internal!(@array $root (-$v) , $($rest)*); }; // Parse positive number `+value`. (@array $root:ident + $v:tt , $($rest:tt)*) => { - $crate::easy::toml_internal!(@array $root ($v) , $($rest)*); + $crate::toml_internal!(@array $root ($v) , $($rest)*); }; // Parse offset datetime `1979-05-27T00:32:00.999999-07:00`. (@array $root:ident $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt . $frac:tt - $tzh:tt : $tzm:tt , $($rest:tt)*) => { - $crate::easy::toml_internal!(@arraydatetime $root ($yr - $mo - $dhr : $min : $sec . $frac - $tzh : $tzm) $($rest)*); + $crate::toml_internal!(@arraydatetime $root ($yr - $mo - $dhr : $min : $sec . $frac - $tzh : $tzm) $($rest)*); }; // Space instead of T. (@array $root:ident $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt . $frac:tt - $tzh:tt : $tzm:tt , $($rest:tt)*) => { - $crate::easy::toml_internal!(@arraydatetime $root ($yr - $mo - $day T $hr : $min : $sec . $frac - $tzh : $tzm) $($rest)*); + $crate::toml_internal!(@arraydatetime $root ($yr - $mo - $day T $hr : $min : $sec . $frac - $tzh : $tzm) $($rest)*); }; // Parse offset datetime `1979-05-27T00:32:00-07:00`. (@array $root:ident $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt - $tzh:tt : $tzm:tt , $($rest:tt)*) => { - $crate::easy::toml_internal!(@arraydatetime $root ($yr - $mo - $dhr : $min : $sec - $tzh : $tzm) $($rest)*); + $crate::toml_internal!(@arraydatetime $root ($yr - $mo - $dhr : $min : $sec - $tzh : $tzm) $($rest)*); }; // Space instead of T. (@array $root:ident $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt - $tzh:tt : $tzm:tt , $($rest:tt)*) => { - $crate::easy::toml_internal!(@arraydatetime $root ($yr - $mo - $day T $hr : $min : $sec - $tzh : $tzm) $($rest)*); + $crate::toml_internal!(@arraydatetime $root ($yr - $mo - $day T $hr : $min : $sec - $tzh : $tzm) $($rest)*); }; // Parse local datetime `1979-05-27T00:32:00.999999`. (@array $root:ident $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt . $frac:tt , $($rest:tt)*) => { - $crate::easy::toml_internal!(@arraydatetime $root ($yr - $mo - $dhr : $min : $sec . $frac) $($rest)*); + $crate::toml_internal!(@arraydatetime $root ($yr - $mo - $dhr : $min : $sec . $frac) $($rest)*); }; // Space instead of T. (@array $root:ident $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt . $frac:tt , $($rest:tt)*) => { - $crate::easy::toml_internal!(@arraydatetime $root ($yr - $mo - $day T $hr : $min : $sec . $frac) $($rest)*); + $crate::toml_internal!(@arraydatetime $root ($yr - $mo - $day T $hr : $min : $sec . $frac) $($rest)*); }; // Parse offset datetime `1979-05-27T07:32:00Z` and local datetime `1979-05-27T07:32:00`. (@array $root:ident $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt , $($rest:tt)*) => { - $crate::easy::toml_internal!(@arraydatetime $root ($yr - $mo - $dhr : $min : $sec) $($rest)*); + $crate::toml_internal!(@arraydatetime $root ($yr - $mo - $dhr : $min : $sec) $($rest)*); }; // Space instead of T. (@array $root:ident $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt , $($rest:tt)*) => { - $crate::easy::toml_internal!(@arraydatetime $root ($yr - $mo - $day T $hr : $min : $sec) $($rest)*); + $crate::toml_internal!(@arraydatetime $root ($yr - $mo - $day T $hr : $min : $sec) $($rest)*); }; // Parse local date `1979-05-27`. (@array $root:ident $yr:tt - $mo:tt - $day:tt , $($rest:tt)*) => { - $crate::easy::toml_internal!(@arraydatetime $root ($yr - $mo - $day) $($rest)*); + $crate::toml_internal!(@arraydatetime $root ($yr - $mo - $day) $($rest)*); }; // Parse local time `00:32:00.999999`. (@array $root:ident $hr:tt : $min:tt : $sec:tt . $frac:tt , $($rest:tt)*) => { - $crate::easy::toml_internal!(@arraydatetime $root ($hr : $min : $sec . $frac) $($rest)*); + $crate::toml_internal!(@arraydatetime $root ($hr : $min : $sec . $frac) $($rest)*); }; // Parse local time `07:32:00`. (@array $root:ident $hr:tt : $min:tt : $sec:tt , $($rest:tt)*) => { - $crate::easy::toml_internal!(@arraydatetime $root ($hr : $min : $sec) $($rest)*); + $crate::toml_internal!(@arraydatetime $root ($hr : $min : $sec) $($rest)*); }; // Parse any other type, probably string or boolean or number. (@array $root:ident $v:tt , $($rest:tt)*) => { - $root.push($crate::easy::toml_internal!(@value $v)); - $crate::easy::toml_internal!(@array $root $($rest)*); + $root.push($crate::toml_internal!(@value $v)); + $crate::toml_internal!(@array $root $($rest)*); }; // Parse a Datetime from string and continue in @array state. (@arraydatetime $root:ident ($($datetime:tt)*) $($rest:tt)*) => { $root.push($crate::easy::Value::Datetime(concat!($(stringify!($datetime)),+).parse().unwrap())); - $crate::easy::toml_internal!(@array $root $($rest)*); + $crate::toml_internal!(@array $root $($rest)*); }; // No trailing comma required if the tokens are empty. (@trailingcomma ($($args:tt)*)) => { - $crate::easy::toml_internal!($($args)*); + $crate::toml_internal!($($args)*); }; // Tokens end with a trailing comma, do not append another one. (@trailingcomma ($($args:tt)*) ,) => { - $crate::easy::toml_internal!($($args)* ,); + $crate::toml_internal!($($args)* ,); }; // Tokens end with something other than comma, append a trailing comma. (@trailingcomma ($($args:tt)*) $last:tt) => { - $crate::easy::toml_internal!($($args)* $last ,); + $crate::toml_internal!($($args)* $last ,); }; // Not yet at the last token. (@trailingcomma ($($args:tt)*) $first:tt $($rest:tt)+) => { - $crate::easy::toml_internal!(@trailingcomma ($($args)* $first) $($rest)+); + $crate::toml_internal!(@trailingcomma ($($args)* $first) $($rest)+); }; } diff --git a/src/easy/mod.rs b/src/easy/mod.rs index 2b2a4c72..59ed5b08 100644 --- a/src/easy/mod.rs +++ b/src/easy/mod.rs @@ -76,8 +76,8 @@ //! //! An example of deserializing with TOML is: //! -//! ```rust -//! use serde_derive::Deserialize; +//! ```rust,ignore +//! use serde::Deserialize; //! //! #[derive(Deserialize)] //! struct Config { @@ -92,26 +92,24 @@ //! travis: Option, //! } //! -//! fn main() { -//! let config: Config = toml_edit::easy::from_str(r#" -//! ip = '127.0.0.1' +//! let config: Config = toml_edit::easy::from_str(r#" +//! ip = '127.0.0.1' //! -//! [keys] -//! github = 'xxxxxxxxxxxxxxxxx' -//! travis = 'yyyyyyyyyyyyyyyyy' -//! "#).unwrap(); +//! [keys] +//! github = 'xxxxxxxxxxxxxxxxx' +//! travis = 'yyyyyyyyyyyyyyyyy' +//! "#).unwrap(); //! -//! assert_eq!(config.ip, "127.0.0.1"); -//! assert_eq!(config.port, None); -//! assert_eq!(config.keys.github, "xxxxxxxxxxxxxxxxx"); -//! assert_eq!(config.keys.travis.as_ref().unwrap(), "yyyyyyyyyyyyyyyyy"); -//! } +//! assert_eq!(config.ip, "127.0.0.1"); +//! assert_eq!(config.port, None); +//! assert_eq!(config.keys.github, "xxxxxxxxxxxxxxxxx"); +//! assert_eq!(config.keys.travis.as_ref().unwrap(), "yyyyyyyyyyyyyyyyy"); //! ``` //! //! You can serialize types in a similar fashion: //! -//! ```rust -//! use serde_derive::Serialize; +//! ```rust,ignore +//! use serde::Serialize; //! //! #[derive(Serialize)] //! struct Config { @@ -126,18 +124,16 @@ //! travis: Option, //! } //! -//! fn main() { -//! let config = Config { -//! ip: "127.0.0.1".to_string(), -//! port: None, -//! keys: Keys { -//! github: "xxxxxxxxxxxxxxxxx".to_string(), -//! travis: Some("yyyyyyyyyyyyyyyyy".to_string()), -//! }, -//! }; -//! -//! let toml = toml_edit::easy::to_string(&config).unwrap(); -//! } +//! let config = Config { +//! ip: "127.0.0.1".to_string(), +//! port: None, +//! keys: Keys { +//! github: "xxxxxxxxxxxxxxxxx".to_string(), +//! travis: Some("yyyyyyyyyyyyyyyyy".to_string()), +//! }, +//! }; +//! +//! let toml = toml_edit::easy::to_string(&config).unwrap(); //! ``` //! //! [TOML]: https://github.com/toml-lang/toml @@ -147,13 +143,14 @@ mod datetime; pub mod de; +#[doc(hidden)] +pub mod macros; pub mod map; pub mod value; -#[doc(no_inline)] -pub use crate::easy::value::Value; +pub use crate::toml; pub use datetime::*; +#[doc(no_inline)] pub use de::{from_document, from_slice, from_str, Deserializer}; - -#[doc(hidden)] -pub mod macros; +#[doc(no_inline)] +pub use value::Value;