More formatting of doc tests and example code

This commit is contained in:
David Tolnay 2023-07-06 15:45:53 -07:00
parent 1920b694aa
commit fa0312ac45
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
11 changed files with 30 additions and 36 deletions

View File

@ -48,7 +48,7 @@ serde_json = "1.0"
<p></p> <p></p>
```rust ```rust
use serde::{Serialize, Deserialize}; use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
struct Point { struct Point {

View File

@ -16,7 +16,7 @@ You may be looking for:
## Serde in action ## Serde in action
```rust ```rust
use serde::{Serialize, Deserialize}; use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
struct Point { struct Point {

View File

@ -11,12 +11,11 @@ use de::{
/// gets deserialized. /// gets deserialized.
/// ///
/// ```edition2021 /// ```edition2021
/// use std::fmt;
/// use std::marker::PhantomData;
///
/// use serde::de::{ /// use serde::de::{
/// self, Deserialize, DeserializeSeed, Deserializer, IgnoredAny, SeqAccess, Visitor, /// self, Deserialize, DeserializeSeed, Deserializer, IgnoredAny, SeqAccess, Visitor,
/// }; /// };
/// use std::fmt;
/// use std::marker::PhantomData;
/// ///
/// /// A seed that can be used to deserialize only the `n`th element of a sequence /// /// A seed that can be used to deserialize only the `n`th element of a sequence
/// /// while efficiently discarding elements of any type before or after index `n`. /// /// while efficiently discarding elements of any type before or after index `n`.

View File

@ -433,9 +433,8 @@ impl<'a> fmt::Display for Unexpected<'a> {
/// (`&self`) is an implementation of this trait. /// (`&self`) is an implementation of this trait.
/// ///
/// ```edition2021 /// ```edition2021
/// # use std::fmt;
/// #
/// # use serde::de::{self, Unexpected, Visitor}; /// # use serde::de::{self, Unexpected, Visitor};
/// # use std::fmt;
/// # /// #
/// # struct Example; /// # struct Example;
/// # /// #
@ -667,11 +666,10 @@ impl<T> DeserializeOwned for T where T: for<'de> Deserialize<'de> {}
/// trait. /// trait.
/// ///
/// ```edition2021 /// ```edition2021
/// use serde::de::{Deserialize, DeserializeSeed, Deserializer, SeqAccess, Visitor};
/// use std::fmt; /// use std::fmt;
/// use std::marker::PhantomData; /// use std::marker::PhantomData;
/// ///
/// use serde::de::{Deserialize, DeserializeSeed, Deserializer, SeqAccess, Visitor};
///
/// // A DeserializeSeed implementation that uses stateful deserialization to /// // A DeserializeSeed implementation that uses stateful deserialization to
/// // append array elements onto the end of an existing vector. The preexisting /// // append array elements onto the end of an existing vector. The preexisting
/// // state ("seed") in this case is the Vec<T>. The `deserialize` method of /// // state ("seed") in this case is the Vec<T>. The `deserialize` method of
@ -1253,9 +1251,8 @@ pub trait Deserializer<'de>: Sized {
/// # Example /// # Example
/// ///
/// ```edition2021 /// ```edition2021
/// # use std::fmt;
/// #
/// # use serde::de::{self, Unexpected, Visitor}; /// # use serde::de::{self, Unexpected, Visitor};
/// # use std::fmt;
/// # /// #
/// /// A visitor that deserializes a long string - a string containing at least /// /// A visitor that deserializes a long string - a string containing at least
/// /// some minimum number of bytes. /// /// some minimum number of bytes.

View File

@ -79,10 +79,9 @@
/// specified explicitly if necessary. /// specified explicitly if necessary.
/// ///
/// ```edition2021 /// ```edition2021
/// # use std::marker::PhantomData;
/// #
/// # use serde::forward_to_deserialize_any; /// # use serde::forward_to_deserialize_any;
/// # use serde::de::{value, Deserializer, Visitor}; /// # use serde::de::{value, Deserializer, Visitor};
/// # use std::marker::PhantomData;
/// # /// #
/// # struct MyDeserializer<V>(PhantomData<V>); /// # struct MyDeserializer<V>(PhantomData<V>);
/// # /// #

View File

@ -1,7 +1,7 @@
//! This crate provides Serde's two derive macros. //! This crate provides Serde's two derive macros.
//! //!
//! ```edition2021 //! ```edition2021
//! # use serde_derive::{Serialize, Deserialize}; //! # use serde_derive::{Deserialize, Serialize};
//! # //! #
//! #[derive(Serialize, Deserialize)] //! #[derive(Serialize, Deserialize)]
//! # struct S; //! # struct S;

View File

@ -9,7 +9,7 @@ use std::fmt::Debug;
/// Runs both `assert_ser_tokens` and `assert_de_tokens`. /// Runs both `assert_ser_tokens` and `assert_de_tokens`.
/// ///
/// ```edition2021 /// ```edition2021
/// # use serde_derive::{Serialize, Deserialize}; /// # use serde_derive::{Deserialize, Serialize};
/// # use serde_test::{assert_tokens, Token}; /// # use serde_test::{assert_tokens, Token};
/// # /// #
/// #[derive(Serialize, Deserialize, PartialEq, Debug)] /// #[derive(Serialize, Deserialize, PartialEq, Debug)]
@ -43,7 +43,7 @@ where
/// Asserts that `value` serializes to the given `tokens`. /// Asserts that `value` serializes to the given `tokens`.
/// ///
/// ```edition2021 /// ```edition2021
/// # use serde_derive::{Serialize, Deserialize}; /// # use serde_derive::{Deserialize, Serialize};
/// # use serde_test::{assert_ser_tokens, Token}; /// # use serde_test::{assert_ser_tokens, Token};
/// # /// #
/// #[derive(Serialize, Deserialize, PartialEq, Debug)] /// #[derive(Serialize, Deserialize, PartialEq, Debug)]
@ -85,11 +85,10 @@ where
/// `error`. /// `error`.
/// ///
/// ```edition2021 /// ```edition2021
/// use std::sync::{Arc, Mutex};
/// use std::thread;
///
/// use serde_derive::Serialize; /// use serde_derive::Serialize;
/// use serde_test::{assert_ser_tokens_error, Token}; /// use serde_test::{assert_ser_tokens_error, Token};
/// use std::sync::{Arc, Mutex};
/// use std::thread;
/// ///
/// #[derive(Serialize)] /// #[derive(Serialize)]
/// struct Example { /// struct Example {
@ -102,7 +101,7 @@ where
/// }; /// };
/// let lock = example.lock.clone(); /// let lock = example.lock.clone();
/// ///
/// let _ = thread::spawn(move || { /// let thread = thread::spawn(move || {
/// // This thread will acquire the mutex first, unwrapping the result /// // This thread will acquire the mutex first, unwrapping the result
/// // of `lock` because the lock has not been poisoned. /// // of `lock` because the lock has not been poisoned.
/// let _guard = lock.lock().unwrap(); /// let _guard = lock.lock().unwrap();
@ -110,8 +109,8 @@ where
/// // This panic while holding the lock (`_guard` is in scope) will /// // This panic while holding the lock (`_guard` is in scope) will
/// // poison the mutex. /// // poison the mutex.
/// panic!() /// panic!()
/// }) /// });
/// .join(); /// thread.join();
/// ///
/// let expected = &[ /// let expected = &[
/// Token::Struct { /// Token::Struct {
@ -143,7 +142,7 @@ where
/// Asserts that the given `tokens` deserialize into `value`. /// Asserts that the given `tokens` deserialize into `value`.
/// ///
/// ```edition2021 /// ```edition2021
/// # use serde_derive::{Serialize, Deserialize}; /// # use serde_derive::{Deserialize, Serialize};
/// # use serde_test::{assert_de_tokens, Token}; /// # use serde_test::{assert_de_tokens, Token};
/// # /// #
/// #[derive(Serialize, Deserialize, PartialEq, Debug)] /// #[derive(Serialize, Deserialize, PartialEq, Debug)]
@ -200,7 +199,7 @@ where
/// Asserts that the given `tokens` yield `error` when deserializing. /// Asserts that the given `tokens` yield `error` when deserializing.
/// ///
/// ```edition2021 /// ```edition2021
/// # use serde_derive::{Serialize, Deserialize}; /// # use serde_derive::{Deserialize, Serialize};
/// # use serde_test::{assert_de_tokens_error, Token}; /// # use serde_test::{assert_de_tokens_error, Token};
/// # /// #
/// #[derive(Serialize, Deserialize, PartialEq, Debug)] /// #[derive(Serialize, Deserialize, PartialEq, Debug)]

View File

@ -183,7 +183,7 @@ pub enum Token {
/// A serialized unit struct of the given name. /// A serialized unit struct of the given name.
/// ///
/// ```edition2021 /// ```edition2021
/// # use serde_derive::{Serialize, Deserialize}; /// # use serde_derive::{Deserialize, Serialize};
/// # use serde_test::{assert_tokens, Token}; /// # use serde_test::{assert_tokens, Token};
/// # /// #
/// # fn main() { /// # fn main() {
@ -198,7 +198,7 @@ pub enum Token {
/// A unit variant of an enum. /// A unit variant of an enum.
/// ///
/// ```edition2021 /// ```edition2021
/// # use serde_derive::{Serialize, Deserialize}; /// # use serde_derive::{Deserialize, Serialize};
/// # use serde_test::{assert_tokens, Token}; /// # use serde_test::{assert_tokens, Token};
/// # /// #
/// # fn main() { /// # fn main() {
@ -227,7 +227,7 @@ pub enum Token {
/// After this header is the value contained in the newtype struct. /// After this header is the value contained in the newtype struct.
/// ///
/// ```edition2021 /// ```edition2021
/// # use serde_derive::{Serialize, Deserialize}; /// # use serde_derive::{Deserialize, Serialize};
/// # use serde_test::{assert_tokens, Token}; /// # use serde_test::{assert_tokens, Token};
/// # /// #
/// # fn main() { /// # fn main() {
@ -248,7 +248,7 @@ pub enum Token {
/// After this header is the value contained in the newtype variant. /// After this header is the value contained in the newtype variant.
/// ///
/// ```edition2021 /// ```edition2021
/// # use serde_derive::{Serialize, Deserialize}; /// # use serde_derive::{Deserialize, Serialize};
/// # use serde_test::{assert_tokens, Token}; /// # use serde_test::{assert_tokens, Token};
/// # /// #
/// # fn main() { /// # fn main() {
@ -329,7 +329,7 @@ pub enum Token {
/// `TupleStructEnd`. /// `TupleStructEnd`.
/// ///
/// ```edition2021 /// ```edition2021
/// # use serde_derive::{Serialize, Deserialize}; /// # use serde_derive::{Deserialize, Serialize};
/// # use serde_test::{assert_tokens, Token}; /// # use serde_test::{assert_tokens, Token};
/// # /// #
/// # fn main() { /// # fn main() {
@ -359,7 +359,7 @@ pub enum Token {
/// `TupleVariantEnd`. /// `TupleVariantEnd`.
/// ///
/// ```edition2021 /// ```edition2021
/// # use serde_derive::{Serialize, Deserialize}; /// # use serde_derive::{Deserialize, Serialize};
/// # use serde_test::{assert_tokens, Token}; /// # use serde_test::{assert_tokens, Token};
/// # /// #
/// # fn main() { /// # fn main() {
@ -428,7 +428,7 @@ pub enum Token {
/// After this header are the fields of the struct, followed by `StructEnd`. /// After this header are the fields of the struct, followed by `StructEnd`.
/// ///
/// ```edition2021 /// ```edition2021
/// # use serde_derive::{Serialize, Deserialize}; /// # use serde_derive::{Deserialize, Serialize};
/// # use serde_test::{assert_tokens, Token}; /// # use serde_test::{assert_tokens, Token};
/// # /// #
/// # fn main() { /// # fn main() {
@ -463,7 +463,7 @@ pub enum Token {
/// `StructVariantEnd`. /// `StructVariantEnd`.
/// ///
/// ```edition2021 /// ```edition2021
/// # use serde_derive::{Serialize, Deserialize}; /// # use serde_derive::{Deserialize, Serialize};
/// # use serde_test::{assert_tokens, Token}; /// # use serde_test::{assert_tokens, Token};
/// # /// #
/// # fn main() { /// # fn main() {
@ -500,7 +500,7 @@ pub enum Token {
/// The header to an enum of the given name. /// The header to an enum of the given name.
/// ///
/// ```edition2021 /// ```edition2021
/// # use serde_derive::{Serialize, Deserialize}; /// # use serde_derive::{Deserialize, Serialize};
/// # use serde_test::{assert_tokens, Token}; /// # use serde_test::{assert_tokens, Token};
/// # /// #
/// # fn main() { /// # fn main() {

View File

@ -19,7 +19,7 @@ fn panic(_info: &core::panic::PanicInfo) -> ! {
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
use serde::{Serialize, Deserialize}; use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
struct Unit; struct Unit;

View File

@ -1,4 +1,4 @@
use serde_derive::{Serialize, Deserialize}; use serde_derive::{Deserialize, Serialize};
mod remote { mod remote {
pub struct S { pub struct S {

View File

@ -1,4 +1,4 @@
use serde_derive::{Serialize, Deserialize}; use serde_derive::{Deserialize, Serialize};
mod remote { mod remote {
pub struct S { pub struct S {