Skip to content
Myr

Merge pull request #2969 from dtolnay/coreprivate

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Reduce visibility of serde_core implementation details

authored by David Tolnay · committed by GitHub · parents 260511d, a9150aa · Browse files · 15 files+372 added−370 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

15 files+372 added−370 removed

  • other:+372 added−370 removed

15 files+372 added−370 removed

modified:serde/src/private/de.rs+4 added-4 removed
14 unmodified lines
15 InternallyTaggedUnitVisitor, TagContentOtherField, TagContentOtherFieldVisitor,16 TagOrContentField, TagOrContentFieldVisitor, TaggedContentVisitor, UntaggedUnitVisitor,17};1819pub use serde_core::de::InPlaceSeed;19pub use serde_core::__private::InPlaceSeed;2021/// If the missing field is of type `Option<T>` then treat is as `None`,22/// otherwise it is an error.23pub fn missing_field<'de, V, E>(field: &'static str) -> Result<V, E>
184 unmodified lines
208209 use crate::lib::*;210211 use crate::de::{212 self, size_hint, Deserialize, DeserializeSeed, Deserializer, EnumAccess, Expected,213 IgnoredAny, MapAccess, SeqAccess, Unexpected, Visitor,212 self, Deserialize, DeserializeSeed, Deserializer, EnumAccess, Expected, IgnoredAny,213 MapAccess, SeqAccess, Unexpected, Visitor,214 };215 pub use serde_core::__private::Content;216 use serde_core::__private::ContentVisitor;216 use serde_core::__private::{size_hint, ContentVisitor};217218 pub fn content_as_str<'a, 'de>(content: &'a Content<'de>) -> Option<&'a str> {219 match *content {220 Content::Str(x) => Some(x),
2977 unmodified lines
modified:serde/src/private/mod.rs+1 added-5 removed
13 unmodified lines
14pub use crate::lib::option::Option::{self, None, Some};15pub use crate::lib::ptr;16pub use crate::lib::result::Result::{self, Err, Ok};1718pub use self::string::from_utf8_lossy;18pub use serde_core::__private::string::from_utf8_lossy;1920#[cfg(any(feature = "alloc", feature = "std"))]21pub use crate::lib::{ToString, Vec};2223mod string {24 pub use serde_core::from_utf8_lossy;25}
modified:serde_core/src/de/impls.rs+9 added-7 removed
2 unmodified lines
3use crate::de::{4 Deserialize, Deserializer, EnumAccess, Error, MapAccess, SeqAccess, Unexpected, VariantAccess,5 Visitor,6};7use crate::private::{self, InPlaceSeed};88use crate::seed::InPlaceSeed;99#[cfg(any(feature = "std", feature = "alloc"))]11use crate::de::size_hint;10use crate::private::size_hint;1112////////////////////////////////////////////////////////////////////////////////1314struct UnitVisitor;
2157 unmodified lines
2172 match value {2173 b"secs" => Ok(Field::Secs),2174 b"nanos" => Ok(Field::Nanos),2175 _ => {2177 let value = crate::lib::from_utf8_lossy(value);2176 let value = private::string::from_utf8_lossy(value);2177 Err(Error::unknown_field(&*value, FIELDS))2178 }2179 }2180 }
282 unmodified lines
2463mod range {2464 use crate::lib::*;24652466 use crate::de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor};2467 use crate::private;24682469 pub const FIELDS: &[&str] = &["start", "end"];24702471 // If this were outside of the serde crate, it would just use:
37 unmodified lines
2509 match value {2510 b"start" => Ok(Field::Start),2511 b"end" => Ok(Field::End),2512 _ => {2513 let value = crate::lib::from_utf8_lossy(value);2513 let value = private::string::from_utf8_lossy(value);2514 Err(Error::unknown_field(&*value, FIELDS))2515 }2516 }2517 }
104 unmodified lines
2622mod range_from {2623 use crate::lib::*;26242625 use crate::de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor};2626 use crate::private;26272628 pub const FIELDS: &[&str] = &["start"];26292630 // If this were outside of the serde crate, it would just use:
34 unmodified lines
2665 {2666 match value {2667 b"start" => Ok(Field::Start),2668 _ => {2668 let value = crate::lib::from_utf8_lossy(value);2669 let value = private::string::from_utf8_lossy(value);2670 Err(Error::unknown_field(&*value, FIELDS))2671 }2672 }2673 }
87 unmodified lines
2761mod range_to {2762 use crate::lib::*;27632764 use crate::de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor};2765 use crate::private;27662767 pub const FIELDS: &[&str] = &["end"];27682769 // If this were outside of the serde crate, it would just use:
34 unmodified lines
2804 {2805 match value {2806 b"end" => Ok(Field::End),2807 _ => {2806 let value = crate::lib::from_utf8_lossy(value);2808 let value = private::string::from_utf8_lossy(value);2809 Err(Error::unknown_field(&*value, FIELDS))2810 }2811 }2812 }
361 unmodified lines
modified:serde_core/src/de/mod.rs+1 added-2 removed
118 unmodified lines
119pub mod value;120121mod ignored_any;122mod impls;123pub mod size_hint;123124pub use self::ignored_any::IgnoredAny;126pub use crate::seed::InPlaceSeed;125pub use crate::private::InPlaceSeed;126#[cfg(all(not(feature = "std"), no_core_error))]127#[doc(no_inline)]128pub use crate::std_error::Error as StdError;129#[cfg(not(any(feature = "std", no_core_error)))]
2264 unmodified lines
deleted:serde_core/src/de/seed.rs-19 removed
1use crate::de::{Deserialize, DeserializeSeed, Deserializer};23/// A DeserializeSeed helper for implementing deserialize_in_place Visitors.4///5/// Wraps a mutable reference and calls deserialize_in_place on it.6pub struct InPlaceSeed<'a, T: 'a>(pub &'a mut T);78impl<'a, 'de, T> DeserializeSeed<'de> for InPlaceSeed<'a, T>9where10 T: Deserialize<'de>,11{12 type Value = ();13 fn deserialize<D>(self, deserializer: D) -> Result<Self::Value, D::Error>14 where15 D: Deserializer<'de>,16 {17 T::deserialize_in_place(deserializer, self.0)18 }19}
deleted:serde_core/src/de/size_hint.rs-33 removed
1//! Provides helpers for creating size hints for container deserialization.2#[cfg(any(feature = "std", feature = "alloc"))]3use crate::lib::*;45/// Extracts the exact size of an iterator if it has a known upper bound and it matches the lower bound.6pub fn from_bounds<I>(iter: &I) -> Option<usize>7where8 I: Iterator,9{10 helper(iter.size_hint())11}1213/// Returns conservative size estimate for a container, clamping the result to a maximum size.14#[cfg(any(feature = "std", feature = "alloc"))]15pub fn cautious<Element>(hint: Option<usize>) -> usize {16 const MAX_PREALLOC_BYTES: usize = 1024 * 1024;1718 if mem::size_of::<Element>() == 0 {19 020 } else {21 cmp::min(22 hint.unwrap_or(0),23 MAX_PREALLOC_BYTES / mem::size_of::<Element>(),24 )25 }26}2728fn helper(bounds: (usize, Option<usize>)) -> Option<usize> {29 match bounds {30 (lower, Some(upper)) if lower == upper => Some(upper),31 _ => None,32 }33}
modified:serde_core/src/de/value.rs+2 added-1 removed
22 unmodified lines
2324use crate::lib::*;2526use self::private::{First, Second};27use crate::de::{self, size_hint, Deserializer, Expected, IntoDeserializer, SeqAccess, Visitor};27use crate::de::{self, Deserializer, Expected, IntoDeserializer, SeqAccess, Visitor};28use crate::private::size_hint;29use crate::ser;3031////////////////////////////////////////////////////////////////////////////////32
1863 unmodified lines
added:serde_core/src/private/content.rs+264 added
1use crate::de::{self, Deserialize, Deserializer, EnumAccess, MapAccess, SeqAccess, Visitor};2use crate::lib::*;3use crate::private::size_hint;45// Used from generated code to buffer the contents of the Deserializer when6// deserializing untagged enums and internally tagged enums.7//8// Not public API. Use serde-value instead.9//10// Obsoleted by format-specific buffer types (https://github.com/serde-rs/serde/pull/2912).11#[derive(Clone)]12#[doc(hidden)]13pub enum Content<'de> {14 Bool(bool),1516 U8(u8),17 U16(u16),18 U32(u32),19 U64(u64),2021 I8(i8),22 I16(i16),23 I32(i32),24 I64(i64),2526 F32(f32),27 F64(f64),2829 Char(char),30 String(String),31 Str(&'de str),32 ByteBuf(Vec<u8>),33 Bytes(&'de [u8]),3435 None,36 Some(Box<Content<'de>>),3738 Unit,39 Newtype(Box<Content<'de>>),40 Seq(Vec<Content<'de>>),41 Map(Vec<(Content<'de>, Content<'de>)>),42}4344impl<'de> Deserialize<'de> for Content<'de> {45 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>46 where47 D: Deserializer<'de>,48 {49 // Untagged and internally tagged enums are only supported in50 // self-describing formats.51 let visitor = ContentVisitor { value: PhantomData };52 deserializer.__deserialize_content_v1(visitor)53 }54}5556#[doc(hidden)]57pub struct ContentVisitor<'de> {58 value: PhantomData<Content<'de>>,59}6061impl<'de> ContentVisitor<'de> {62 pub fn new() -> Self {63 ContentVisitor { value: PhantomData }64 }65}6667impl<'de> Visitor<'de> for ContentVisitor<'de> {68 type Value = Content<'de>;6970 fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {71 fmt.write_str("any value")72 }7374 fn visit_bool<F>(self, value: bool) -> Result<Self::Value, F>75 where76 F: de::Error,77 {78 Ok(Content::Bool(value))79 }8081 fn visit_i8<F>(self, value: i8) -> Result<Self::Value, F>82 where83 F: de::Error,84 {85 Ok(Content::I8(value))86 }8788 fn visit_i16<F>(self, value: i16) -> Result<Self::Value, F>89 where90 F: de::Error,91 {92 Ok(Content::I16(value))93 }9495 fn visit_i32<F>(self, value: i32) -> Result<Self::Value, F>96 where97 F: de::Error,98 {99 Ok(Content::I32(value))100 }101102 fn visit_i64<F>(self, value: i64) -> Result<Self::Value, F>103 where104 F: de::Error,105 {106 Ok(Content::I64(value))107 }108109 fn visit_u8<F>(self, value: u8) -> Result<Self::Value, F>110 where111 F: de::Error,112 {113 Ok(Content::U8(value))114 }115116 fn visit_u16<F>(self, value: u16) -> Result<Self::Value, F>117 where118 F: de::Error,119 {120 Ok(Content::U16(value))121 }122123 fn visit_u32<F>(self, value: u32) -> Result<Self::Value, F>124 where125 F: de::Error,126 {127 Ok(Content::U32(value))128 }129130 fn visit_u64<F>(self, value: u64) -> Result<Self::Value, F>131 where132 F: de::Error,133 {134 Ok(Content::U64(value))135 }136137 fn visit_f32<F>(self, value: f32) -> Result<Self::Value, F>138 where139 F: de::Error,140 {141 Ok(Content::F32(value))142 }143144 fn visit_f64<F>(self, value: f64) -> Result<Self::Value, F>145 where146 F: de::Error,147 {148 Ok(Content::F64(value))149 }150151 fn visit_char<F>(self, value: char) -> Result<Self::Value, F>152 where153 F: de::Error,154 {155 Ok(Content::Char(value))156 }157158 fn visit_str<F>(self, value: &str) -> Result<Self::Value, F>159 where160 F: de::Error,161 {162 Ok(Content::String(value.into()))163 }164165 fn visit_borrowed_str<F>(self, value: &'de str) -> Result<Self::Value, F>166 where167 F: de::Error,168 {169 Ok(Content::Str(value))170 }171172 fn visit_string<F>(self, value: String) -> Result<Self::Value, F>173 where174 F: de::Error,175 {176 Ok(Content::String(value))177 }178179 fn visit_bytes<F>(self, value: &[u8]) -> Result<Self::Value, F>180 where181 F: de::Error,182 {183 Ok(Content::ByteBuf(value.into()))184 }185186 fn visit_borrowed_bytes<F>(self, value: &'de [u8]) -> Result<Self::Value, F>187 where188 F: de::Error,189 {190 Ok(Content::Bytes(value))191 }192193 fn visit_byte_buf<F>(self, value: Vec<u8>) -> Result<Self::Value, F>194 where195 F: de::Error,196 {197 Ok(Content::ByteBuf(value))198 }199200 fn visit_unit<F>(self) -> Result<Self::Value, F>201 where202 F: de::Error,203 {204 Ok(Content::Unit)205 }206207 fn visit_none<F>(self) -> Result<Self::Value, F>208 where209 F: de::Error,210 {211 Ok(Content::None)212 }213214 fn visit_some<D>(self, deserializer: D) -> Result<Self::Value, D::Error>215 where216 D: Deserializer<'de>,217 {218 let v = tri!(Deserialize::deserialize(deserializer));219 Ok(Content::Some(Box::new(v)))220 }221222 fn visit_newtype_struct<D>(self, deserializer: D) -> Result<Self::Value, D::Error>223 where224 D: Deserializer<'de>,225 {226 let v = tri!(Deserialize::deserialize(deserializer));227 Ok(Content::Newtype(Box::new(v)))228 }229230 fn visit_seq<V>(self, mut visitor: V) -> Result<Self::Value, V::Error>231 where232 V: SeqAccess<'de>,233 {234 let mut vec =235 Vec::<Content>::with_capacity(size_hint::cautious::<Content>(visitor.size_hint()));236 while let Some(e) = tri!(visitor.next_element()) {237 vec.push(e);238 }239 Ok(Content::Seq(vec))240 }241242 fn visit_map<V>(self, mut visitor: V) -> Result<Self::Value, V::Error>243 where244 V: MapAccess<'de>,245 {246 let mut vec = Vec::<(Content, Content)>::with_capacity(size_hint::cautious::<(247 Content,248 Content,249 )>(visitor.size_hint()));250 while let Some(kv) = tri!(visitor.next_entry()) {251 vec.push(kv);252 }253 Ok(Content::Map(vec))254 }255256 fn visit_enum<V>(self, _visitor: V) -> Result<Self::Value, V::Error>257 where258 V: EnumAccess<'de>,259 {260 Err(de::Error::custom(261 "untagged and internally tagged enums do not support enum input",262 ))263 }264}
added:serde_core/src/private/mod.rs+17 added
1#[cfg(all(not(no_serde_derive), any(feature = "std", feature = "alloc")))]2mod content;3mod seed;45#[doc(hidden)]6pub mod size_hint;78#[doc(hidden)]9pub mod string;1011#[cfg(all(not(no_serde_derive), any(feature = "std", feature = "alloc")))]12#[doc(hidden)]13pub use self::content::{Content, ContentVisitor};14#[doc(hidden)]15pub use self::seed::InPlaceSeed;16#[doc(hidden)]17pub use crate::lib::result::Result;
added:serde_core/src/private/seed.rs+19 added
1use crate::de::{Deserialize, DeserializeSeed, Deserializer};23/// A DeserializeSeed helper for implementing deserialize_in_place Visitors.4///5/// Wraps a mutable reference and calls deserialize_in_place on it.6pub struct InPlaceSeed<'a, T: 'a>(pub &'a mut T);78impl<'a, 'de, T> DeserializeSeed<'de> for InPlaceSeed<'a, T>9where10 T: Deserialize<'de>,11{12 type Value = ();13 fn deserialize<D>(self, deserializer: D) -> Result<Self::Value, D::Error>14 where15 D: Deserializer<'de>,16 {17 T::deserialize_in_place(deserializer, self.0)18 }19}
added:serde_core/src/private/size_hint.rs+30 added
1#[cfg(any(feature = "std", feature = "alloc"))]2use crate::lib::*;34pub fn from_bounds<I>(iter: &I) -> Option<usize>5where6 I: Iterator,7{8 helper(iter.size_hint())9}1011#[cfg(any(feature = "std", feature = "alloc"))]12pub fn cautious<Element>(hint: Option<usize>) -> usize {13 const MAX_PREALLOC_BYTES: usize = 1024 * 1024;1415 if mem::size_of::<Element>() == 0 {16 017 } else {18 cmp::min(19 hint.unwrap_or(0),20 MAX_PREALLOC_BYTES / mem::size_of::<Element>(),21 )22 }23}2425fn helper(bounds: (usize, Option<usize>)) -> Option<usize> {26 match bounds {27 (lower, Some(upper)) if lower == upper => Some(upper),28 _ => None,29 }30}
added:serde_core/src/private/string.rs+23 added
1use crate::lib::*;23#[cfg(any(feature = "std", feature = "alloc"))]4#[doc(hidden)]5pub fn from_utf8_lossy(bytes: &[u8]) -> Cow<'_, str> {6 String::from_utf8_lossy(bytes)7}89// The generated code calls this like:10//11// let value = &_serde::__private::from_utf8_lossy(bytes);12// Err(_serde::de::Error::unknown_variant(value, VARIANTS))13//14// so it is okay for the return type to be different from the std case as long15// as the above works.16#[cfg(not(any(feature = "std", feature = "alloc")))]17#[doc(hidden)]18pub fn from_utf8_lossy(bytes: &[u8]) -> &str {19 // Three unicode replacement characters if it fails. They look like a20 // white-on-black question mark. The user will recognize it as invalid21 // UTF-8.22 str::from_utf8(bytes).unwrap_or("\u{fffd}\u{fffd}\u{fffd}")23}
modified:serde_core/src/lib.rs+1 added-33 removed
101 unmodified lines
102 #[cfg(any(feature = "std", feature = "alloc"))]103 pub use self::core::{cmp, mem};104105 pub use self::core::cell::{Cell, RefCell};106106 pub use self::core::cmp::Reverse;107 pub use self::core::fmt::{self, Debug, Display, Write as FmtWrite};108 pub use self::core::marker::PhantomData;109 pub use self::core::num::Wrapping;
91 unmodified lines
201 pub use std::sync::atomic::{AtomicIsize, AtomicUsize};202203 #[cfg(not(no_core_num_saturating))]204 pub use self::core::num::Saturating;206 #[cfg(any(feature = "std", feature = "alloc"))]207 #[doc(hidden)]208 pub fn from_utf8_lossy(bytes: &[u8]) -> Cow<'_, str> {209 String::from_utf8_lossy(bytes)210 }211212 // The generated code calls this like:213 //214 // let value = &_serde::__private::from_utf8_lossy(bytes);215 // Err(_serde::de::Error::unknown_variant(value, VARIANTS))216 //217 // so it is okay for the return type to be different from the std case as long218 // as the above works.219 #[cfg(not(any(feature = "std", feature = "alloc")))]220 #[doc(hidden)]221 pub fn from_utf8_lossy(bytes: &[u8]) -> &str {222 // Three unicode replacement characters if it fails. They look like a223 // white-on-black question mark. The user will recognize it as invalid224 // UTF-8.225 str::from_utf8(bytes).unwrap_or("\u{fffd}\u{fffd}\u{fffd}")226 }205}206207// None of this crate's error handling needs the `From::from` error conversion208// performed implicitly by the `?` operator or the standard library's `try!`
11 unmodified lines
220////////////////////////////////////////////////////////////////////////////////221222#[macro_use]223mod macros;246#[doc(hidden)]247pub use crate::lib::result::Result;224225#[macro_use]226mod integer128;227
6 unmodified lines
234pub use crate::de::{Deserialize, Deserializer};235#[doc(inline)]236pub use crate::ser::{Serialize, Serializer};237262#[doc(hidden)]263pub use lib::from_utf8_lossy;264238// Used by generated code. Not public API.266#[cfg(all(not(no_serde_derive), any(feature = "std", feature = "alloc")))]239#[doc(hidden)]268#[path = "private.rs"]240#[path = "private/mod.rs"]241pub mod __private;270#[cfg(all(not(no_serde_derive), any(feature = "std", feature = "alloc")))]242use self::__private as private;243273#[path = "de/seed.rs"]274mod seed;275244#[cfg(all(not(feature = "std"), no_core_error))]245mod std_error;246247#[macro_export]
8 unmodified lines
modified:serde_core/src/macros.rs+1 added-1 removed
120 unmodified lines
121#[macro_export]122macro_rules! forward_to_deserialize_any_method {123 ($func:ident<$l:tt, $v:ident>($($arg:ident : $ty:ty),*)) => {124 #[inline]125 fn $func<$v>(self, $($arg: $ty,)* visitor: $v) -> $crate::Result<$v::Value, <Self as $crate::de::Deserializer<$l>>::Error>125 fn $func<$v>(self, $($arg: $ty,)* visitor: $v) -> $crate::__private::Result<$v::Value, <Self as $crate::de::Deserializer<$l>>::Error>126 where127 $v: $crate::de::Visitor<$l>,128 {129 $(
101 unmodified lines
deleted:serde_core/src/private.rs-265 removed
1use crate::de::{2 self, size_hint, Deserialize, Deserializer, EnumAccess, MapAccess, SeqAccess, Visitor,3};4use crate::lib::*;56// Used from generated code to buffer the contents of the Deserializer when7// deserializing untagged enums and internally tagged enums.8//9// Not public API. Use serde-value instead.10//11// Obsoleted by format-specific buffer types (https://github.com/serde-rs/serde/pull/2912).12#[derive(Clone)]13#[doc(hidden)]14pub enum Content<'de> {15 Bool(bool),1617 U8(u8),18 U16(u16),19 U32(u32),20 U64(u64),2122 I8(i8),23 I16(i16),24 I32(i32),25 I64(i64),2627 F32(f32),28 F64(f64),2930 Char(char),31 String(String),32 Str(&'de str),33 ByteBuf(Vec<u8>),34 Bytes(&'de [u8]),3536 None,37 Some(Box<Content<'de>>),3839 Unit,40 Newtype(Box<Content<'de>>),41 Seq(Vec<Content<'de>>),42 Map(Vec<(Content<'de>, Content<'de>)>),43}4445impl<'de> Deserialize<'de> for Content<'de> {46 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>47 where48 D: Deserializer<'de>,49 {50 // Untagged and internally tagged enums are only supported in51 // self-describing formats.52 let visitor = ContentVisitor { value: PhantomData };53 deserializer.__deserialize_content_v1(visitor)54 }55}5657#[doc(hidden)]58pub struct ContentVisitor<'de> {59 value: PhantomData<Content<'de>>,60}6162impl<'de> ContentVisitor<'de> {63 pub fn new() -> Self {64 ContentVisitor { value: PhantomData }65 }66}6768impl<'de> Visitor<'de> for ContentVisitor<'de> {69 type Value = Content<'de>;7071 fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {72 fmt.write_str("any value")73 }7475 fn visit_bool<F>(self, value: bool) -> Result<Self::Value, F>76 where77 F: de::Error,78 {79 Ok(Content::Bool(value))80 }8182 fn visit_i8<F>(self, value: i8) -> Result<Self::Value, F>83 where84 F: de::Error,85 {86 Ok(Content::I8(value))87 }8889 fn visit_i16<F>(self, value: i16) -> Result<Self::Value, F>90 where91 F: de::Error,92 {93 Ok(Content::I16(value))94 }9596 fn visit_i32<F>(self, value: i32) -> Result<Self::Value, F>97 where98 F: de::Error,99 {100 Ok(Content::I32(value))101 }102103 fn visit_i64<F>(self, value: i64) -> Result<Self::Value, F>104 where105 F: de::Error,106 {107 Ok(Content::I64(value))108 }109110 fn visit_u8<F>(self, value: u8) -> Result<Self::Value, F>111 where112 F: de::Error,113 {114 Ok(Content::U8(value))115 }116117 fn visit_u16<F>(self, value: u16) -> Result<Self::Value, F>118 where119 F: de::Error,120 {121 Ok(Content::U16(value))122 }123124 fn visit_u32<F>(self, value: u32) -> Result<Self::Value, F>125 where126 F: de::Error,127 {128 Ok(Content::U32(value))129 }130131 fn visit_u64<F>(self, value: u64) -> Result<Self::Value, F>132 where133 F: de::Error,134 {135 Ok(Content::U64(value))136 }137138 fn visit_f32<F>(self, value: f32) -> Result<Self::Value, F>139 where140 F: de::Error,141 {142 Ok(Content::F32(value))143 }144145 fn visit_f64<F>(self, value: f64) -> Result<Self::Value, F>146 where147 F: de::Error,148 {149 Ok(Content::F64(value))150 }151152 fn visit_char<F>(self, value: char) -> Result<Self::Value, F>153 where154 F: de::Error,155 {156 Ok(Content::Char(value))157 }158159 fn visit_str<F>(self, value: &str) -> Result<Self::Value, F>160 where161 F: de::Error,162 {163 Ok(Content::String(value.into()))164 }165166 fn visit_borrowed_str<F>(self, value: &'de str) -> Result<Self::Value, F>167 where168 F: de::Error,169 {170 Ok(Content::Str(value))171 }172173 fn visit_string<F>(self, value: String) -> Result<Self::Value, F>174 where175 F: de::Error,176 {177 Ok(Content::String(value))178 }179180 fn visit_bytes<F>(self, value: &[u8]) -> Result<Self::Value, F>181 where182 F: de::Error,183 {184 Ok(Content::ByteBuf(value.into()))185 }186187 fn visit_borrowed_bytes<F>(self, value: &'de [u8]) -> Result<Self::Value, F>188 where189 F: de::Error,190 {191 Ok(Content::Bytes(value))192 }193194 fn visit_byte_buf<F>(self, value: Vec<u8>) -> Result<Self::Value, F>195 where196 F: de::Error,197 {198 Ok(Content::ByteBuf(value))199 }200201 fn visit_unit<F>(self) -> Result<Self::Value, F>202 where203 F: de::Error,204 {205 Ok(Content::Unit)206 }207208 fn visit_none<F>(self) -> Result<Self::Value, F>209 where210 F: de::Error,211 {212 Ok(Content::None)213 }214215 fn visit_some<D>(self, deserializer: D) -> Result<Self::Value, D::Error>216 where217 D: Deserializer<'de>,218 {219 let v = tri!(Deserialize::deserialize(deserializer));220 Ok(Content::Some(Box::new(v)))221 }222223 fn visit_newtype_struct<D>(self, deserializer: D) -> Result<Self::Value, D::Error>224 where225 D: Deserializer<'de>,226 {227 let v = tri!(Deserialize::deserialize(deserializer));228 Ok(Content::Newtype(Box::new(v)))229 }230231 fn visit_seq<V>(self, mut visitor: V) -> Result<Self::Value, V::Error>232 where233 V: SeqAccess<'de>,234 {235 let mut vec =236 Vec::<Content>::with_capacity(size_hint::cautious::<Content>(visitor.size_hint()));237 while let Some(e) = tri!(visitor.next_element()) {238 vec.push(e);239 }240 Ok(Content::Seq(vec))241 }242243 fn visit_map<V>(self, mut visitor: V) -> Result<Self::Value, V::Error>244 where245 V: MapAccess<'de>,246 {247 let mut vec = Vec::<(Content, Content)>::with_capacity(size_hint::cautious::<(248 Content,249 Content,250 )>(visitor.size_hint()));251 while let Some(kv) = tri!(visitor.next_entry()) {252 vec.push(kv);253 }254 Ok(Content::Map(vec))255 }256257 fn visit_enum<V>(self, _visitor: V) -> Result<Self::Value, V::Error>258 where259 V: EnumAccess<'de>,260 {261 Err(de::Error::custom(262 "untagged and internally tagged enums do not support enum input",263 ))264 }265}