Vendor things
This commit is contained in:
parent
5deceec006
commit
977e3c17e5
19434 changed files with 10682014 additions and 0 deletions
170
third-party/vendor/serde/src/ser/fmt.rs
vendored
Normal file
170
third-party/vendor/serde/src/ser/fmt.rs
vendored
Normal file
|
|
@ -0,0 +1,170 @@
|
|||
use crate::lib::*;
|
||||
use crate::ser::{Error, Impossible, Serialize, Serializer};
|
||||
|
||||
impl Error for fmt::Error {
|
||||
fn custom<T: Display>(_msg: T) -> Self {
|
||||
fmt::Error
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! fmt_primitives {
|
||||
($($f:ident: $t:ty,)*) => {
|
||||
$(
|
||||
fn $f(self, v: $t) -> fmt::Result {
|
||||
Display::fmt(&v, self)
|
||||
}
|
||||
)*
|
||||
};
|
||||
}
|
||||
|
||||
/// ```edition2021
|
||||
/// use serde::ser::Serialize;
|
||||
/// use serde_derive::Serialize;
|
||||
/// use std::fmt::{self, Display};
|
||||
///
|
||||
/// #[derive(Serialize)]
|
||||
/// #[serde(rename_all = "kebab-case")]
|
||||
/// pub enum MessageType {
|
||||
/// StartRequest,
|
||||
/// EndRequest,
|
||||
/// }
|
||||
///
|
||||
/// impl Display for MessageType {
|
||||
/// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
/// self.serialize(f)
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
impl<'a, 'b> Serializer for &'a mut fmt::Formatter<'b> {
|
||||
type Ok = ();
|
||||
type Error = fmt::Error;
|
||||
type SerializeSeq = Impossible<(), fmt::Error>;
|
||||
type SerializeTuple = Impossible<(), fmt::Error>;
|
||||
type SerializeTupleStruct = Impossible<(), fmt::Error>;
|
||||
type SerializeTupleVariant = Impossible<(), fmt::Error>;
|
||||
type SerializeMap = Impossible<(), fmt::Error>;
|
||||
type SerializeStruct = Impossible<(), fmt::Error>;
|
||||
type SerializeStructVariant = Impossible<(), fmt::Error>;
|
||||
|
||||
fmt_primitives! {
|
||||
serialize_bool: bool,
|
||||
serialize_i8: i8,
|
||||
serialize_i16: i16,
|
||||
serialize_i32: i32,
|
||||
serialize_i64: i64,
|
||||
serialize_i128: i128,
|
||||
serialize_u8: u8,
|
||||
serialize_u16: u16,
|
||||
serialize_u32: u32,
|
||||
serialize_u64: u64,
|
||||
serialize_u128: u128,
|
||||
serialize_f32: f32,
|
||||
serialize_f64: f64,
|
||||
serialize_char: char,
|
||||
serialize_str: &str,
|
||||
serialize_unit_struct: &'static str,
|
||||
}
|
||||
|
||||
fn serialize_unit_variant(
|
||||
self,
|
||||
_name: &'static str,
|
||||
_variant_index: u32,
|
||||
variant: &'static str,
|
||||
) -> fmt::Result {
|
||||
Display::fmt(variant, self)
|
||||
}
|
||||
|
||||
fn serialize_newtype_struct<T: ?Sized>(self, _name: &'static str, value: &T) -> fmt::Result
|
||||
where
|
||||
T: Serialize,
|
||||
{
|
||||
Serialize::serialize(value, self)
|
||||
}
|
||||
|
||||
fn serialize_bytes(self, _v: &[u8]) -> fmt::Result {
|
||||
Err(fmt::Error)
|
||||
}
|
||||
|
||||
fn serialize_none(self) -> fmt::Result {
|
||||
Err(fmt::Error)
|
||||
}
|
||||
|
||||
fn serialize_some<T: ?Sized>(self, _value: &T) -> fmt::Result
|
||||
where
|
||||
T: Serialize,
|
||||
{
|
||||
Err(fmt::Error)
|
||||
}
|
||||
|
||||
fn serialize_unit(self) -> fmt::Result {
|
||||
Err(fmt::Error)
|
||||
}
|
||||
|
||||
fn serialize_newtype_variant<T: ?Sized>(
|
||||
self,
|
||||
_name: &'static str,
|
||||
_variant_index: u32,
|
||||
_variant: &'static str,
|
||||
_value: &T,
|
||||
) -> fmt::Result
|
||||
where
|
||||
T: Serialize,
|
||||
{
|
||||
Err(fmt::Error)
|
||||
}
|
||||
|
||||
fn serialize_seq(self, _len: Option<usize>) -> Result<Self::SerializeSeq, fmt::Error> {
|
||||
Err(fmt::Error)
|
||||
}
|
||||
|
||||
fn serialize_tuple(self, _len: usize) -> Result<Self::SerializeTuple, fmt::Error> {
|
||||
Err(fmt::Error)
|
||||
}
|
||||
|
||||
fn serialize_tuple_struct(
|
||||
self,
|
||||
_name: &'static str,
|
||||
_len: usize,
|
||||
) -> Result<Self::SerializeTupleStruct, fmt::Error> {
|
||||
Err(fmt::Error)
|
||||
}
|
||||
|
||||
fn serialize_tuple_variant(
|
||||
self,
|
||||
_name: &'static str,
|
||||
_variant_index: u32,
|
||||
_variant: &'static str,
|
||||
_len: usize,
|
||||
) -> Result<Self::SerializeTupleVariant, fmt::Error> {
|
||||
Err(fmt::Error)
|
||||
}
|
||||
|
||||
fn serialize_map(self, _len: Option<usize>) -> Result<Self::SerializeMap, fmt::Error> {
|
||||
Err(fmt::Error)
|
||||
}
|
||||
|
||||
fn serialize_struct(
|
||||
self,
|
||||
_name: &'static str,
|
||||
_len: usize,
|
||||
) -> Result<Self::SerializeStruct, fmt::Error> {
|
||||
Err(fmt::Error)
|
||||
}
|
||||
|
||||
fn serialize_struct_variant(
|
||||
self,
|
||||
_name: &'static str,
|
||||
_variant_index: u32,
|
||||
_variant: &'static str,
|
||||
_len: usize,
|
||||
) -> Result<Self::SerializeStructVariant, fmt::Error> {
|
||||
Err(fmt::Error)
|
||||
}
|
||||
|
||||
fn collect_str<T: ?Sized>(self, value: &T) -> fmt::Result
|
||||
where
|
||||
T: Display,
|
||||
{
|
||||
Display::fmt(value, self)
|
||||
}
|
||||
}
|
||||
1077
third-party/vendor/serde/src/ser/impls.rs
vendored
Normal file
1077
third-party/vendor/serde/src/ser/impls.rs
vendored
Normal file
File diff suppressed because it is too large
Load diff
216
third-party/vendor/serde/src/ser/impossible.rs
vendored
Normal file
216
third-party/vendor/serde/src/ser/impossible.rs
vendored
Normal file
|
|
@ -0,0 +1,216 @@
|
|||
//! This module contains `Impossible` serializer and its implementations.
|
||||
|
||||
use crate::lib::*;
|
||||
|
||||
use crate::ser::{
|
||||
self, Serialize, SerializeMap, SerializeSeq, SerializeStruct, SerializeStructVariant,
|
||||
SerializeTuple, SerializeTupleStruct, SerializeTupleVariant,
|
||||
};
|
||||
|
||||
/// Helper type for implementing a `Serializer` that does not support
|
||||
/// serializing one of the compound types.
|
||||
///
|
||||
/// This type cannot be instantiated, but implements every one of the traits
|
||||
/// corresponding to the [`Serializer`] compound types: [`SerializeSeq`],
|
||||
/// [`SerializeTuple`], [`SerializeTupleStruct`], [`SerializeTupleVariant`],
|
||||
/// [`SerializeMap`], [`SerializeStruct`], and [`SerializeStructVariant`].
|
||||
///
|
||||
/// ```edition2021
|
||||
/// # use serde::ser::{Serializer, Impossible};
|
||||
/// # use serde::__private::doc::Error;
|
||||
/// #
|
||||
/// # struct MySerializer;
|
||||
/// #
|
||||
/// impl Serializer for MySerializer {
|
||||
/// type Ok = ();
|
||||
/// type Error = Error;
|
||||
///
|
||||
/// type SerializeSeq = Impossible<(), Error>;
|
||||
/// /* other associated types */
|
||||
///
|
||||
/// /// This data format does not support serializing sequences.
|
||||
/// fn serialize_seq(self,
|
||||
/// len: Option<usize>)
|
||||
/// -> Result<Self::SerializeSeq, Error> {
|
||||
/// // Given Impossible cannot be instantiated, the only
|
||||
/// // thing we can do here is to return an error.
|
||||
/// # stringify! {
|
||||
/// Err(...)
|
||||
/// # };
|
||||
/// # unimplemented!()
|
||||
/// }
|
||||
///
|
||||
/// /* other Serializer methods */
|
||||
/// # serde::__serialize_unimplemented! {
|
||||
/// # bool i8 i16 i32 i64 u8 u16 u32 u64 f32 f64 char str bytes none some
|
||||
/// # unit unit_struct unit_variant newtype_struct newtype_variant
|
||||
/// # tuple tuple_struct tuple_variant map struct struct_variant
|
||||
/// # }
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// [`Serializer`]: trait.Serializer.html
|
||||
/// [`SerializeSeq`]: trait.SerializeSeq.html
|
||||
/// [`SerializeTuple`]: trait.SerializeTuple.html
|
||||
/// [`SerializeTupleStruct`]: trait.SerializeTupleStruct.html
|
||||
/// [`SerializeTupleVariant`]: trait.SerializeTupleVariant.html
|
||||
/// [`SerializeMap`]: trait.SerializeMap.html
|
||||
/// [`SerializeStruct`]: trait.SerializeStruct.html
|
||||
/// [`SerializeStructVariant`]: trait.SerializeStructVariant.html
|
||||
pub struct Impossible<Ok, Error> {
|
||||
void: Void,
|
||||
ok: PhantomData<Ok>,
|
||||
error: PhantomData<Error>,
|
||||
}
|
||||
|
||||
enum Void {}
|
||||
|
||||
impl<Ok, Error> SerializeSeq for Impossible<Ok, Error>
|
||||
where
|
||||
Error: ser::Error,
|
||||
{
|
||||
type Ok = Ok;
|
||||
type Error = Error;
|
||||
|
||||
fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<(), Error>
|
||||
where
|
||||
T: Serialize,
|
||||
{
|
||||
let _ = value;
|
||||
match self.void {}
|
||||
}
|
||||
|
||||
fn end(self) -> Result<Ok, Error> {
|
||||
match self.void {}
|
||||
}
|
||||
}
|
||||
|
||||
impl<Ok, Error> SerializeTuple for Impossible<Ok, Error>
|
||||
where
|
||||
Error: ser::Error,
|
||||
{
|
||||
type Ok = Ok;
|
||||
type Error = Error;
|
||||
|
||||
fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<(), Error>
|
||||
where
|
||||
T: Serialize,
|
||||
{
|
||||
let _ = value;
|
||||
match self.void {}
|
||||
}
|
||||
|
||||
fn end(self) -> Result<Ok, Error> {
|
||||
match self.void {}
|
||||
}
|
||||
}
|
||||
|
||||
impl<Ok, Error> SerializeTupleStruct for Impossible<Ok, Error>
|
||||
where
|
||||
Error: ser::Error,
|
||||
{
|
||||
type Ok = Ok;
|
||||
type Error = Error;
|
||||
|
||||
fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), Error>
|
||||
where
|
||||
T: Serialize,
|
||||
{
|
||||
let _ = value;
|
||||
match self.void {}
|
||||
}
|
||||
|
||||
fn end(self) -> Result<Ok, Error> {
|
||||
match self.void {}
|
||||
}
|
||||
}
|
||||
|
||||
impl<Ok, Error> SerializeTupleVariant for Impossible<Ok, Error>
|
||||
where
|
||||
Error: ser::Error,
|
||||
{
|
||||
type Ok = Ok;
|
||||
type Error = Error;
|
||||
|
||||
fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), Error>
|
||||
where
|
||||
T: Serialize,
|
||||
{
|
||||
let _ = value;
|
||||
match self.void {}
|
||||
}
|
||||
|
||||
fn end(self) -> Result<Ok, Error> {
|
||||
match self.void {}
|
||||
}
|
||||
}
|
||||
|
||||
impl<Ok, Error> SerializeMap for Impossible<Ok, Error>
|
||||
where
|
||||
Error: ser::Error,
|
||||
{
|
||||
type Ok = Ok;
|
||||
type Error = Error;
|
||||
|
||||
fn serialize_key<T: ?Sized>(&mut self, key: &T) -> Result<(), Error>
|
||||
where
|
||||
T: Serialize,
|
||||
{
|
||||
let _ = key;
|
||||
match self.void {}
|
||||
}
|
||||
|
||||
fn serialize_value<T: ?Sized>(&mut self, value: &T) -> Result<(), Error>
|
||||
where
|
||||
T: Serialize,
|
||||
{
|
||||
let _ = value;
|
||||
match self.void {}
|
||||
}
|
||||
|
||||
fn end(self) -> Result<Ok, Error> {
|
||||
match self.void {}
|
||||
}
|
||||
}
|
||||
|
||||
impl<Ok, Error> SerializeStruct for Impossible<Ok, Error>
|
||||
where
|
||||
Error: ser::Error,
|
||||
{
|
||||
type Ok = Ok;
|
||||
type Error = Error;
|
||||
|
||||
fn serialize_field<T: ?Sized>(&mut self, key: &'static str, value: &T) -> Result<(), Error>
|
||||
where
|
||||
T: Serialize,
|
||||
{
|
||||
let _ = key;
|
||||
let _ = value;
|
||||
match self.void {}
|
||||
}
|
||||
|
||||
fn end(self) -> Result<Ok, Error> {
|
||||
match self.void {}
|
||||
}
|
||||
}
|
||||
|
||||
impl<Ok, Error> SerializeStructVariant for Impossible<Ok, Error>
|
||||
where
|
||||
Error: ser::Error,
|
||||
{
|
||||
type Ok = Ok;
|
||||
type Error = Error;
|
||||
|
||||
fn serialize_field<T: ?Sized>(&mut self, key: &'static str, value: &T) -> Result<(), Error>
|
||||
where
|
||||
T: Serialize,
|
||||
{
|
||||
let _ = key;
|
||||
let _ = value;
|
||||
match self.void {}
|
||||
}
|
||||
|
||||
fn end(self) -> Result<Ok, Error> {
|
||||
match self.void {}
|
||||
}
|
||||
}
|
||||
1952
third-party/vendor/serde/src/ser/mod.rs
vendored
Normal file
1952
third-party/vendor/serde/src/ser/mod.rs
vendored
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue