Move doctest-only helpers to a doc module

This commit is contained in:
David Tolnay 2021-01-23 22:24:20 -08:00
parent 9fd56cd41c
commit e61261e002
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
6 changed files with 36 additions and 33 deletions

View File

@ -10,7 +10,7 @@
/// bother with this macro and may assume support for 128-bit integers.
///
/// ```edition2018
/// # use serde::__private::ser::Error;
/// # use serde::__private::doc::Error;
/// #
/// # struct MySerializer;
/// #

View File

@ -1,3 +1,35 @@
// Used only by Serde doc tests. Not public API.
use lib::*;
use ser;
#[doc(hidden)]
#[derive(Debug)]
pub struct Error;
impl ser::Error for Error {
fn custom<T>(_: T) -> Self
where
T: Display,
{
unimplemented!()
}
}
#[cfg(feature = "std")]
impl error::Error for Error {
fn description(&self) -> &str {
unimplemented!()
}
}
impl Display for Error {
fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result {
unimplemented!()
}
}
#[doc(hidden)]
#[macro_export]
macro_rules! __private_serialize {
@ -10,7 +42,6 @@ macro_rules! __private_serialize {
};
}
/// Used only by Serde doc tests. Not public API.
#[doc(hidden)]
#[macro_export(local_inner_macros)]
macro_rules! __serialize_unimplemented {

View File

@ -1,6 +1,5 @@
mod macros;
pub mod de;
pub mod doc;
pub mod ser;
pub use lib::clone::Clone;

View File

@ -335,33 +335,6 @@ where
}
}
/// Used only by Serde doc tests. Not public API.
#[doc(hidden)]
#[derive(Debug)]
pub struct Error;
impl ser::Error for Error {
fn custom<T>(_: T) -> Self
where
T: Display,
{
unimplemented!()
}
}
#[cfg(feature = "std")]
impl error::Error for Error {
fn description(&self) -> &str {
unimplemented!()
}
}
impl Display for Error {
fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result {
unimplemented!()
}
}
#[cfg(any(feature = "std", feature = "alloc"))]
mod content {
use lib::*;

View File

@ -17,7 +17,7 @@ use ser::{
///
/// ```edition2018
/// # use serde::ser::{Serializer, Impossible};
/// # use serde::__private::ser::Error;
/// # use serde::__private::doc::Error;
/// #
/// # struct MySerializer;
/// #

View File

@ -711,7 +711,7 @@ pub trait Serializer: Sized {
///
/// ```edition2018
/// # use serde::ser::{Serializer, SerializeSeq};
/// # use serde::__private::ser::Error;
/// # use serde::__private::doc::Error;
/// #
/// # struct MySerializer;
/// #