From e71b8598aecf15c561decb5409414e0b9693b242 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 31 Dec 2018 22:38:14 -0500 Subject: [PATCH] Update serde_test examples to 2018 edition --- serde_test/Cargo.toml | 2 +- serde_test/src/assert.rs | 80 ++++++++--------------- serde_test/src/configure.rs | 5 +- serde_test/src/lib.rs | 15 +---- serde_test/src/token.rs | 123 ++++++++++++------------------------ 5 files changed, 72 insertions(+), 153 deletions(-) diff --git a/serde_test/Cargo.toml b/serde_test/Cargo.toml index 4eab43f2..1f0973ef 100644 --- a/serde_test/Cargo.toml +++ b/serde_test/Cargo.toml @@ -15,7 +15,7 @@ include = ["Cargo.toml", "src/**/*.rs", "crates-io.md", "README.md", "LICENSE-AP serde = { version = "1.0.60", path = "../serde" } [dev-dependencies] -serde = { version = "1.0", path = "../serde", features = ["rc"] } +serde = { version = "1.0", path = "../serde", features = ["rc", "derive"] } serde_derive = { version = "1.0", path = "../serde_derive" } [badges] diff --git a/serde_test/src/assert.rs b/serde_test/src/assert.rs index 11130791..ecbba1b8 100644 --- a/serde_test/src/assert.rs +++ b/serde_test/src/assert.rs @@ -8,13 +8,8 @@ use std::fmt::Debug; /// Runs both `assert_ser_tokens` and `assert_de_tokens`. /// -/// ```rust -/// # #[macro_use] -/// # extern crate serde_derive; -/// # -/// # extern crate serde; -/// # extern crate serde_test; -/// # +/// ```edition2018 +/// # use serde::{Serialize, Deserialize}; /// # use serde_test::{assert_tokens, Token}; /// # /// # fn main() { @@ -45,13 +40,8 @@ where /// Asserts that `value` serializes to the given `tokens`. /// -/// ```rust -/// # #[macro_use] -/// # extern crate serde_derive; -/// # -/// # extern crate serde; -/// # extern crate serde_test; -/// # +/// ```edition2018 +/// # use serde::{Serialize, Deserialize}; /// # use serde_test::{assert_ser_tokens, Token}; /// # /// # fn main() { @@ -90,16 +80,11 @@ where /// Asserts that `value` serializes to the given `tokens`, and then yields /// `error`. /// -/// ```rust -/// # #[macro_use] -/// # extern crate serde_derive; -/// # -/// # extern crate serde_test; -/// # -/// # fn main() { +/// ```edition2018 /// use std::sync::{Arc, Mutex}; /// use std::thread; /// +/// use serde::Serialize; /// use serde_test::{assert_ser_tokens_error, Token}; /// /// #[derive(Serialize)] @@ -107,26 +92,27 @@ where /// lock: Arc>, /// } /// -/// let example = Example { lock: Arc::new(Mutex::new(0)) }; -/// let lock = example.lock.clone(); +/// fn main() { +/// let example = Example { lock: Arc::new(Mutex::new(0)) }; +/// let lock = example.lock.clone(); /// -/// let _ = thread::spawn(move || { -/// // This thread will acquire the mutex first, unwrapping the result -/// // of `lock` because the lock has not been poisoned. -/// let _guard = lock.lock().unwrap(); +/// let _ = thread::spawn(move || { +/// // This thread will acquire the mutex first, unwrapping the result +/// // of `lock` because the lock has not been poisoned. +/// let _guard = lock.lock().unwrap(); /// -/// // This panic while holding the lock (`_guard` is in scope) will -/// // poison the mutex. -/// panic!() -/// }).join(); +/// // This panic while holding the lock (`_guard` is in scope) will +/// // poison the mutex. +/// panic!() +/// }).join(); /// -/// let expected = &[ -/// Token::Struct { name: "Example", len: 1 }, -/// Token::Str("lock"), -/// ]; -/// let error = "lock poison error while serializing"; -/// assert_ser_tokens_error(&example, expected, error); -/// # } +/// let expected = &[ +/// Token::Struct { name: "Example", len: 1 }, +/// Token::Str("lock"), +/// ]; +/// let error = "lock poison error while serializing"; +/// assert_ser_tokens_error(&example, expected, error); +/// } /// ``` pub fn assert_ser_tokens_error(value: &T, tokens: &[Token], error: &str) where @@ -145,13 +131,8 @@ where /// Asserts that the given `tokens` deserialize into `value`. /// -/// ```rust -/// # #[macro_use] -/// # extern crate serde_derive; -/// # -/// # extern crate serde; -/// # extern crate serde_test; -/// # +/// ```edition2018 +/// # use serde::{Serialize, Deserialize}; /// # use serde_test::{assert_de_tokens, Token}; /// # /// # fn main() { @@ -205,13 +186,8 @@ where /// Asserts that the given `tokens` yield `error` when deserializing. /// -/// ```rust -/// # #[macro_use] -/// # extern crate serde_derive; -/// # -/// # extern crate serde; -/// # extern crate serde_test; -/// # +/// ```edition2018 +/// # use serde::{Serialize, Deserialize}; /// # use serde_test::{assert_de_tokens_error, Token}; /// # /// # fn main() { diff --git a/serde_test/src/configure.rs b/serde_test/src/configure.rs index d66e4f21..fb962c39 100644 --- a/serde_test/src/configure.rs +++ b/serde_test/src/configure.rs @@ -14,10 +14,7 @@ pub struct Compact(T); /// Trait to determine whether a value is represented in human-readable or /// compact form. /// -/// ``` -/// extern crate serde; -/// extern crate serde_test; -/// +/// ```edition2018 /// use serde::{Deserialize, Deserializer, Serialize, Serializer}; /// use serde_test::{assert_tokens, Configure, Token}; /// diff --git a/serde_test/src/lib.rs b/serde_test/src/lib.rs index d22d790e..bc5675a0 100644 --- a/serde_test/src/lib.rs +++ b/serde_test/src/lib.rs @@ -24,19 +24,10 @@ //! //! [`linked-hash-map`]: https://github.com/contain-rs/linked-hash-map //! -//! ```rust -//! # extern crate serde; -//! # -//! # macro_rules! ignore { -//! # ($($tt:tt)+) => {} -//! # } -//! # -//! # ignore! { -//! extern crate linked_hash_map; +//! ```edition2018 +//! # const IGNORE: &str = stringify! { //! use linked_hash_map::LinkedHashMap; -//! # } -//! -//! extern crate serde_test; +//! # }; //! use serde_test::{Token, assert_tokens}; //! //! # use std::fmt; diff --git a/serde_test/src/token.rs b/serde_test/src/token.rs index 80d6978c..0ebd8c50 100644 --- a/serde_test/src/token.rs +++ b/serde_test/src/token.rs @@ -4,7 +4,7 @@ use std::fmt::{self, Debug, Display}; pub enum Token { /// A serialized `bool`. /// - /// ```rust + /// ``` /// # use serde_test::{assert_tokens, Token}; /// # /// assert_tokens(&true, &[Token::Bool(true)]); @@ -13,7 +13,7 @@ pub enum Token { /// A serialized `i8`. /// - /// ```rust + /// ``` /// # use serde_test::{assert_tokens, Token}; /// # /// assert_tokens(&0i8, &[Token::I8(0)]); @@ -22,7 +22,7 @@ pub enum Token { /// A serialized `i16`. /// - /// ```rust + /// ``` /// # use serde_test::{assert_tokens, Token}; /// # /// assert_tokens(&0i16, &[Token::I16(0)]); @@ -31,7 +31,7 @@ pub enum Token { /// A serialized `i32`. /// - /// ```rust + /// ``` /// # use serde_test::{assert_tokens, Token}; /// # /// assert_tokens(&0i32, &[Token::I32(0)]); @@ -40,7 +40,7 @@ pub enum Token { /// A serialized `i64`. /// - /// ```rust + /// ``` /// # use serde_test::{assert_tokens, Token}; /// # /// assert_tokens(&0i64, &[Token::I64(0)]); @@ -49,7 +49,7 @@ pub enum Token { /// A serialized `u8`. /// - /// ```rust + /// ``` /// # use serde_test::{assert_tokens, Token}; /// # /// assert_tokens(&0u8, &[Token::U8(0)]); @@ -58,7 +58,7 @@ pub enum Token { /// A serialized `u16`. /// - /// ```rust + /// ``` /// # use serde_test::{assert_tokens, Token}; /// # /// assert_tokens(&0u16, &[Token::U16(0)]); @@ -67,7 +67,7 @@ pub enum Token { /// A serialized `u32`. /// - /// ```rust + /// ``` /// # use serde_test::{assert_tokens, Token}; /// # /// assert_tokens(&0u32, &[Token::U32(0)]); @@ -76,7 +76,7 @@ pub enum Token { /// A serialized `u64`. /// - /// ```rust + /// ``` /// # use serde_test::{assert_tokens, Token}; /// # /// assert_tokens(&0u64, &[Token::U64(0)]); @@ -85,7 +85,7 @@ pub enum Token { /// A serialized `f32`. /// - /// ```rust + /// ``` /// # use serde_test::{assert_tokens, Token}; /// # /// assert_tokens(&0f32, &[Token::F32(0.0)]); @@ -94,7 +94,7 @@ pub enum Token { /// A serialized `f64`. /// - /// ```rust + /// ``` /// # use serde_test::{assert_tokens, Token}; /// # /// assert_tokens(&0f64, &[Token::F64(0.0)]); @@ -103,7 +103,7 @@ pub enum Token { /// A serialized `char`. /// - /// ```rust + /// ``` /// # use serde_test::{assert_tokens, Token}; /// # /// assert_tokens(&'\n', &[Token::Char('\n')]); @@ -112,7 +112,7 @@ pub enum Token { /// A serialized `str`. /// - /// ```rust + /// ``` /// # use serde_test::{assert_tokens, Token}; /// # /// let s = String::from("transient"); @@ -122,7 +122,7 @@ pub enum Token { /// A borrowed `str`. /// - /// ```rust + /// ``` /// # use serde_test::{assert_tokens, Token}; /// # /// let s: &str = "borrowed"; @@ -132,7 +132,7 @@ pub enum Token { /// A serialized `String`. /// - /// ```rust + /// ``` /// # use serde_test::{assert_tokens, Token}; /// # /// let s = String::from("owned"); @@ -151,7 +151,7 @@ pub enum Token { /// A serialized `Option` containing none. /// - /// ```rust + /// ``` /// # use serde_test::{assert_tokens, Token}; /// # /// let opt = None::; @@ -163,7 +163,7 @@ pub enum Token { /// /// The tokens of the value follow after this header. /// - /// ```rust + /// ``` /// # use serde_test::{assert_tokens, Token}; /// # /// let opt = Some('c'); @@ -176,7 +176,7 @@ pub enum Token { /// A serialized `()`. /// - /// ```rust + /// ``` /// # use serde_test::{assert_tokens, Token}; /// # /// assert_tokens(&(), &[Token::Unit]); @@ -185,13 +185,8 @@ pub enum Token { /// A serialized unit struct of the given name. /// - /// ```rust - /// # #[macro_use] - /// # extern crate serde_derive; - /// # - /// # extern crate serde; - /// # extern crate serde_test; - /// # + /// ```edition2018 + /// # use serde::{Serialize, Deserialize}; /// # use serde_test::{assert_tokens, Token}; /// # /// # fn main() { @@ -205,13 +200,8 @@ pub enum Token { /// A unit variant of an enum. /// - /// ```rust - /// # #[macro_use] - /// # extern crate serde_derive; - /// # - /// # extern crate serde; - /// # extern crate serde_test; - /// # + /// ```edition2018 + /// # use serde::{Serialize, Deserialize}; /// # use serde_test::{assert_tokens, Token}; /// # /// # fn main() { @@ -233,13 +223,8 @@ pub enum Token { /// /// After this header is the value contained in the newtype struct. /// - /// ```rust - /// # #[macro_use] - /// # extern crate serde_derive; - /// # - /// # extern crate serde; - /// # extern crate serde_test; - /// # + /// ```edition2018 + /// # use serde::{Serialize, Deserialize}; /// # use serde_test::{assert_tokens, Token}; /// # /// # fn main() { @@ -259,13 +244,8 @@ pub enum Token { /// /// After this header is the value contained in the newtype variant. /// - /// ```rust - /// # #[macro_use] - /// # extern crate serde_derive; - /// # - /// # extern crate serde; - /// # extern crate serde_test; - /// # + /// ```edition2018 + /// # use serde::{Serialize, Deserialize}; /// # use serde_test::{assert_tokens, Token}; /// # /// # fn main() { @@ -291,7 +271,7 @@ pub enum Token { /// After this header are the elements of the sequence, followed by /// `SeqEnd`. /// - /// ```rust + /// ``` /// # use serde_test::{assert_tokens, Token}; /// # /// let vec = vec!['a', 'b', 'c']; @@ -312,7 +292,7 @@ pub enum Token { /// /// After this header are the elements of the tuple, followed by `TupleEnd`. /// - /// ```rust + /// ``` /// # use serde_test::{assert_tokens, Token}; /// # /// let tuple = ('a', 100); @@ -333,13 +313,8 @@ pub enum Token { /// After this header are the fields of the tuple struct, followed by /// `TupleStructEnd`. /// - /// ```rust - /// # #[macro_use] - /// # extern crate serde_derive; - /// # - /// # extern crate serde; - /// # extern crate serde_test; - /// # + /// ```edition2018 + /// # use serde::{Serialize, Deserialize}; /// # use serde_test::{assert_tokens, Token}; /// # /// # fn main() { @@ -365,13 +340,8 @@ pub enum Token { /// After this header are the fields of the tuple variant, followed by /// `TupleVariantEnd`. /// - /// ```rust - /// # #[macro_use] - /// # extern crate serde_derive; - /// # - /// # extern crate serde; - /// # extern crate serde_test; - /// # + /// ```edition2018 + /// # use serde::{Serialize, Deserialize}; /// # use serde_test::{assert_tokens, Token}; /// # /// # fn main() { @@ -402,7 +372,7 @@ pub enum Token { /// /// After this header are the entries of the map, followed by `MapEnd`. /// - /// ```rust + /// ``` /// # use serde_test::{assert_tokens, Token}; /// # /// use std::collections::BTreeMap; @@ -429,13 +399,8 @@ pub enum Token { /// /// After this header are the fields of the struct, followed by `StructEnd`. /// - /// ```rust - /// # #[macro_use] - /// # extern crate serde_derive; - /// # - /// # extern crate serde; - /// # extern crate serde_test; - /// # + /// ```edition2018 + /// # use serde::{Serialize, Deserialize}; /// # use serde_test::{assert_tokens, Token}; /// # /// # fn main() { @@ -466,13 +431,8 @@ pub enum Token { /// After this header are the fields of the struct variant, followed by /// `StructVariantEnd`. /// - /// ```rust - /// # #[macro_use] - /// # extern crate serde_derive; - /// # - /// # extern crate serde; - /// # extern crate serde_test; - /// # + /// ```edition2018 + /// # use serde::{Serialize, Deserialize}; /// # use serde_test::{assert_tokens, Token}; /// # /// # fn main() { @@ -501,13 +461,8 @@ pub enum Token { /// The header to an enum of the given name. /// - /// ```rust - /// # #[macro_use] - /// # extern crate serde_derive; - /// # - /// # extern crate serde; - /// # extern crate serde_test; - /// # + /// ```edition2018 + /// # use serde::{Serialize, Deserialize}; /// # use serde_test::{assert_tokens, Token}; /// # /// # fn main() {