mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-14 23:11:01 +00:00
All combinations of features compile without warnings
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
#[cfg(all(feature = "unstable", feature = "collections", not(feature = "std")))]
|
#[cfg(all(feature = "collections", not(feature = "std")))]
|
||||||
use collections::borrow::Cow;
|
use collections::borrow::Cow;
|
||||||
|
|
||||||
#[cfg(all(feature = "collections", not(feature = "std")))]
|
#[cfg(all(feature = "collections", not(feature = "std")))]
|
||||||
@@ -27,12 +27,13 @@ use std::collections::{
|
|||||||
VecDeque,
|
VecDeque,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(all(feature = "unstable", feature = "collections"))]
|
#[cfg(feature = "collections")]
|
||||||
use collections::enum_set::{CLike, EnumSet};
|
use collections::enum_set::{CLike, EnumSet};
|
||||||
#[cfg(all(feature = "unstable", feature = "collections"))]
|
#[cfg(feature = "collections")]
|
||||||
use collections::borrow::ToOwned;
|
use collections::borrow::ToOwned;
|
||||||
|
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
|
#[cfg(feature = "std")]
|
||||||
use core::hash::{Hash, BuildHasher};
|
use core::hash::{Hash, BuildHasher};
|
||||||
use core::marker::PhantomData;
|
use core::marker::PhantomData;
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
@@ -43,15 +44,15 @@ use core::str;
|
|||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
#[cfg(all(feature = "unstable", feature = "alloc", not(feature = "std")))]
|
#[cfg(all(feature = "alloc", not(feature = "std")))]
|
||||||
use alloc::rc::Rc;
|
use alloc::rc::Rc;
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
#[cfg(all(feature = "unstable", feature = "alloc", not(feature = "std")))]
|
#[cfg(all(feature = "alloc", not(feature = "std")))]
|
||||||
use alloc::arc::Arc;
|
use alloc::arc::Arc;
|
||||||
|
|
||||||
#[cfg(all(feature = "unstable", feature = "alloc", not(feature = "std")))]
|
#[cfg(all(feature = "alloc", not(feature = "std")))]
|
||||||
use alloc::boxed::Box;
|
use alloc::boxed::Box;
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
@@ -482,7 +483,7 @@ seq_impl!(
|
|||||||
BTreeSet::new(),
|
BTreeSet::new(),
|
||||||
BTreeSet::insert);
|
BTreeSet::insert);
|
||||||
|
|
||||||
#[cfg(all(feature = "unstable", feature = "collections"))]
|
#[cfg(feature = "collections")]
|
||||||
seq_impl!(
|
seq_impl!(
|
||||||
EnumSet<T>,
|
EnumSet<T>,
|
||||||
EnumSetVisitor<T: Deserialize + CLike>,
|
EnumSetVisitor<T: Deserialize + CLike>,
|
||||||
|
|||||||
+1
-1
@@ -415,7 +415,7 @@ pub trait Deserialize: Sized {
|
|||||||
/// to deserialize it into a flat representation like `vec![1, 2, 3, 4, 5, 6]`.
|
/// to deserialize it into a flat representation like `vec![1, 2, 3, 4, 5, 6]`.
|
||||||
/// Allocating a brand new `Vec<T>` for each subarray would be slow. Instead we
|
/// Allocating a brand new `Vec<T>` for each subarray would be slow. Instead we
|
||||||
/// would like to allocate a single `Vec<T>` and then deserialize each subarray
|
/// would like to allocate a single `Vec<T>` and then deserialize each subarray
|
||||||
/// into it. This requires stateful deserialization using the DeserializeSeed
|
/// into it. This requires stateful deserialization using the `DeserializeSeed`
|
||||||
/// trait.
|
/// trait.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
|||||||
+8
-10
@@ -33,9 +33,7 @@ use collections::boxed::Box;
|
|||||||
#[cfg(all(feature = "collections", not(feature = "std")))]
|
#[cfg(all(feature = "collections", not(feature = "std")))]
|
||||||
use collections::string::ToString;
|
use collections::string::ToString;
|
||||||
|
|
||||||
#[cfg(all(feature = "unstable", feature = "collections"))]
|
#[cfg(feature = "std")]
|
||||||
use collections::borrow::ToOwned;
|
|
||||||
|
|
||||||
use core::hash::Hash;
|
use core::hash::Hash;
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
use std::error;
|
use std::error;
|
||||||
@@ -67,7 +65,7 @@ impl de::Error for Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(feature = "std", feature = "collections")))]
|
#[cfg(not(any(feature = "std", feature = "collections")))]
|
||||||
fn custom<T: Display>(msg: T) -> Self {
|
fn custom<T: Display>(_msg: T) -> Self {
|
||||||
Error(())
|
Error(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -579,7 +577,7 @@ impl<I, E> MapDeserializer<I, E>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn next(&mut self) -> Option<(<I::Item as private::Pair>::First, <I::Item as private::Pair>::Second)> {
|
fn next_pair(&mut self) -> Option<(<I::Item as private::Pair>::First, <I::Item as private::Pair>::Second)> {
|
||||||
match self.iter.next() {
|
match self.iter.next() {
|
||||||
Some(kv) => {
|
Some(kv) => {
|
||||||
self.count += 1;
|
self.count += 1;
|
||||||
@@ -654,7 +652,7 @@ impl<I, E> de::MapVisitor for MapDeserializer<I, E>
|
|||||||
fn visit_key_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error>
|
fn visit_key_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error>
|
||||||
where T: de::DeserializeSeed,
|
where T: de::DeserializeSeed,
|
||||||
{
|
{
|
||||||
match self.next() {
|
match self.next_pair() {
|
||||||
Some((key, value)) => {
|
Some((key, value)) => {
|
||||||
self.value = Some(value);
|
self.value = Some(value);
|
||||||
seed.deserialize(key.into_deserializer()).map(Some)
|
seed.deserialize(key.into_deserializer()).map(Some)
|
||||||
@@ -677,7 +675,7 @@ impl<I, E> de::MapVisitor for MapDeserializer<I, E>
|
|||||||
where TK: de::DeserializeSeed,
|
where TK: de::DeserializeSeed,
|
||||||
TV: de::DeserializeSeed
|
TV: de::DeserializeSeed
|
||||||
{
|
{
|
||||||
match self.next() {
|
match self.next_pair() {
|
||||||
Some((key, value)) => {
|
Some((key, value)) => {
|
||||||
let key = try!(kseed.deserialize(key.into_deserializer()));
|
let key = try!(kseed.deserialize(key.into_deserializer()));
|
||||||
let value = try!(vseed.deserialize(value.into_deserializer()));
|
let value = try!(vseed.deserialize(value.into_deserializer()));
|
||||||
@@ -704,7 +702,7 @@ impl<I, E> de::SeqVisitor for MapDeserializer<I, E>
|
|||||||
fn visit_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error>
|
fn visit_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error>
|
||||||
where T: de::DeserializeSeed,
|
where T: de::DeserializeSeed,
|
||||||
{
|
{
|
||||||
match self.next() {
|
match self.next_pair() {
|
||||||
Some((k, v)) => {
|
Some((k, v)) => {
|
||||||
let de = PairDeserializer(k, v, PhantomData);
|
let de = PairDeserializer(k, v, PhantomData);
|
||||||
seed.deserialize(de).map(Some)
|
seed.deserialize(de).map(Some)
|
||||||
@@ -993,8 +991,8 @@ mod private {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Avoid having to restate the generic types on MapDeserializer. The
|
/// Avoid having to restate the generic types on `MapDeserializer`. The
|
||||||
/// Iterator::Item contains enough information to figure out K and V.
|
/// `Iterator::Item` contains enough information to figure out K and V.
|
||||||
pub trait Pair {
|
pub trait Pair {
|
||||||
type First;
|
type First;
|
||||||
type Second;
|
type Second;
|
||||||
|
|||||||
+10
-11
@@ -11,30 +11,29 @@
|
|||||||
|
|
||||||
#![doc(html_root_url="https://docs.serde.rs")]
|
#![doc(html_root_url="https://docs.serde.rs")]
|
||||||
#![cfg_attr(not(feature = "std"), no_std)]
|
#![cfg_attr(not(feature = "std"), no_std)]
|
||||||
#![cfg_attr(feature = "unstable", feature(reflect_marker, unicode, nonzero, plugin, step_trait, zero_one, inclusive_range))]
|
#![cfg_attr(feature = "unstable", feature(nonzero, inclusive_range, zero_one))]
|
||||||
#![cfg_attr(feature = "alloc", feature(alloc))]
|
#![cfg_attr(feature = "alloc", feature(alloc))]
|
||||||
#![cfg_attr(feature = "collections", feature(collections, enumset))]
|
#![cfg_attr(feature = "collections", feature(collections, enumset))]
|
||||||
|
#![cfg_attr(feature = "clippy", feature(plugin))]
|
||||||
#![cfg_attr(feature = "clippy", plugin(clippy))]
|
#![cfg_attr(feature = "clippy", plugin(clippy))]
|
||||||
#![cfg_attr(feature = "clippy", allow(linkedlist))]
|
#![cfg_attr(feature = "clippy", allow(linkedlist, type_complexity))]
|
||||||
|
|
||||||
#![cfg_attr(any(not(feature = "std"), feature = "unstable"), allow(unused_variables, unused_imports, unused_features, dead_code))]
|
|
||||||
|
|
||||||
#![deny(missing_docs)]
|
#![deny(missing_docs)]
|
||||||
|
|
||||||
#[cfg(all(feature = "unstable", feature = "collections"))]
|
#[cfg(feature = "collections")]
|
||||||
extern crate collections;
|
extern crate collections;
|
||||||
|
|
||||||
#[cfg(all(feature = "unstable", feature = "alloc"))]
|
#[cfg(feature = "alloc")]
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|
||||||
|
#[cfg(feature = "unstable")]
|
||||||
|
extern crate core as actual_core;
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
mod core {
|
mod core {
|
||||||
pub use std::{ops, hash, fmt, cmp, marker, mem, i8, i16, i32, i64, u8, u16, u32, u64, isize,
|
pub use std::{ops, hash, fmt, cmp, marker, mem, i8, i16, i32, i64, u8, u16, u32, u64, isize,
|
||||||
usize, f32, f64, char, str, num, slice, iter, cell};
|
usize, f32, f64, char, str, num, slice, iter, cell};
|
||||||
#[cfg(feature = "unstable")]
|
#[cfg(feature = "unstable")]
|
||||||
extern crate core;
|
pub use actual_core::nonzero;
|
||||||
#[cfg(feature = "unstable")]
|
|
||||||
pub use self::core::nonzero;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub use ser::{Serialize, Serializer};
|
pub use ser::{Serialize, Serializer};
|
||||||
@@ -48,6 +47,6 @@ pub mod de;
|
|||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub mod iter;
|
pub mod iter;
|
||||||
pub mod ser;
|
pub mod ser;
|
||||||
#[cfg(not(feature = "std"))]
|
#[cfg_attr(feature = "std", doc(hidden))]
|
||||||
pub mod error;
|
pub mod error;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|||||||
@@ -30,19 +30,18 @@ use collections::{
|
|||||||
Vec,
|
Vec,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(all(feature = "unstable", feature = "collections"))]
|
#[cfg(feature = "collections")]
|
||||||
use collections::enum_set::{CLike, EnumSet};
|
use collections::enum_set::{CLike, EnumSet};
|
||||||
#[cfg(all(feature = "unstable", feature = "collections"))]
|
#[cfg(feature = "collections")]
|
||||||
use collections::borrow::ToOwned;
|
use collections::borrow::ToOwned;
|
||||||
|
|
||||||
|
#[cfg(feature = "std")]
|
||||||
use core::hash::{Hash, BuildHasher};
|
use core::hash::{Hash, BuildHasher};
|
||||||
#[cfg(feature = "unstable")]
|
#[cfg(feature = "unstable")]
|
||||||
use core::iter;
|
use core::iter;
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
use std::net;
|
use std::net;
|
||||||
#[cfg(feature = "unstable")]
|
#[cfg(feature = "unstable")]
|
||||||
use core::num;
|
|
||||||
#[cfg(feature = "unstable")]
|
|
||||||
use core::ops;
|
use core::ops;
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
use std::path;
|
use std::path;
|
||||||
@@ -67,14 +66,13 @@ use core::marker::PhantomData;
|
|||||||
use core::nonzero::{NonZero, Zeroable};
|
use core::nonzero::{NonZero, Zeroable};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
Error,
|
|
||||||
Serialize,
|
Serialize,
|
||||||
SerializeMap,
|
|
||||||
SerializeSeq,
|
SerializeSeq,
|
||||||
SerializeStruct,
|
|
||||||
SerializeTuple,
|
SerializeTuple,
|
||||||
Serializer,
|
Serializer,
|
||||||
};
|
};
|
||||||
|
#[cfg(any(feature = "std", feature = "unstable"))]
|
||||||
|
use super::Error;
|
||||||
|
|
||||||
#[cfg(feature = "unstable")]
|
#[cfg(feature = "unstable")]
|
||||||
use super::Iterator;
|
use super::Iterator;
|
||||||
@@ -241,7 +239,7 @@ impl<'a, I> Serialize for Iterator<I>
|
|||||||
// FIXME: use specialization to prevent invalidating the object in case of clonable iterators?
|
// FIXME: use specialization to prevent invalidating the object in case of clonable iterators?
|
||||||
let iter = match self.0.borrow_mut().take() {
|
let iter = match self.0.borrow_mut().take() {
|
||||||
Some(iter) => iter.into_iter(),
|
Some(iter) => iter.into_iter(),
|
||||||
None => return Err(S::Error::custom("Iterator used twice")),
|
None => return Err(Error::custom("Iterator used twice")),
|
||||||
};
|
};
|
||||||
let size = match iter.size_hint() {
|
let size = match iter.size_hint() {
|
||||||
(lo, Some(hi)) if lo == hi => Some(lo),
|
(lo, Some(hi)) if lo == hi => Some(lo),
|
||||||
@@ -286,7 +284,7 @@ impl<T> Serialize for BTreeSet<T>
|
|||||||
serialize_seq!();
|
serialize_seq!();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(feature = "unstable", feature = "collections"))]
|
#[cfg(feature = "collections")]
|
||||||
impl<T> Serialize for EnumSet<T>
|
impl<T> Serialize for EnumSet<T>
|
||||||
where T: Serialize + CLike
|
where T: Serialize + CLike
|
||||||
{
|
{
|
||||||
@@ -573,6 +571,7 @@ macro_rules! serialize_map {
|
|||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
where S: Serializer,
|
where S: Serializer,
|
||||||
{
|
{
|
||||||
|
use super::SerializeMap;
|
||||||
let mut map = try!(serializer.serialize_map(Some(self.len())));
|
let mut map = try!(serializer.serialize_map(Some(self.len())));
|
||||||
for (k, v) in self {
|
for (k, v) in self {
|
||||||
try!(map.serialize_key(k));
|
try!(map.serialize_key(k));
|
||||||
@@ -695,6 +694,7 @@ impl Serialize for Duration {
|
|||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
where S: Serializer,
|
where S: Serializer,
|
||||||
{
|
{
|
||||||
|
use super::SerializeStruct;
|
||||||
let mut state = try!(serializer.serialize_struct("Duration", 2));
|
let mut state = try!(serializer.serialize_struct("Duration", 2));
|
||||||
try!(state.serialize_field("secs", self.as_secs()));
|
try!(state.serialize_field("secs", self.as_secs()));
|
||||||
try!(state.serialize_field("nanos", self.subsec_nanos()));
|
try!(state.serialize_field("nanos", self.subsec_nanos()));
|
||||||
|
|||||||
@@ -15,11 +15,6 @@ use std::error;
|
|||||||
#[cfg(not(feature = "std"))]
|
#[cfg(not(feature = "std"))]
|
||||||
use error;
|
use error;
|
||||||
|
|
||||||
#[cfg(all(feature = "collections", not(feature = "std")))]
|
|
||||||
use collections::String;
|
|
||||||
|
|
||||||
#[cfg(feature = "unstable")]
|
|
||||||
use core::marker::PhantomData;
|
|
||||||
#[cfg(feature = "unstable")]
|
#[cfg(feature = "unstable")]
|
||||||
use core::cell::RefCell;
|
use core::cell::RefCell;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user