| 1 | #![cfg(feature = "serde")] |
| 2 | |
| 3 | use superrust-analyzer cargo mediatype 0.23.0 crate/::{media_typerust-analyzer cargo mediatype 0.23.0 media_type/::*, media_type_bufrust-analyzer cargo mediatype 0.23.0 media_type_buf/::*}; |
| 4 | use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::{borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#, stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/::ToStringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/ToString#}; |
| 5 | use serderust-analyzer cargo serde 1.0.218 crate/::{Deserializerust-analyzer cargo serde 1.0.218 de/Deserialize#, Deserializerrust-analyzer cargo serde 1.0.218 de/Deserializer#, Serializerust-analyzer cargo serde 1.0.218 ser/Serialize#, Serializerrust-analyzer cargo serde 1.0.218 ser/Serializer#}; |
| 6 | |
| 7 | impl Serializerust-analyzer cargo serde 1.0.218 ser/Serialize# for MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#<'_> { |
| 8 | fn serializerust-analyzer cargo mediatype 0.23.0 serde/impl#[`MediaType<'_>`][Serialize]serialize().<S>(&self, serializer: S) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<S::Okrust-analyzer cargo serde 1.0.218 ser/Serializer#Ok#, S::Errorrust-analyzer cargo serde 1.0.218 ser/Serializer#Error#> |
| 9 | where |
| 10 | S: Serializerrust-analyzer cargo serde 1.0.218 ser/Serializer#, |
| 11 | { |
| 12 | self.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().serializerust-analyzer cargo serde 1.0.218 ser/impls/impl#[String][Serialize]serialize().(serializer) |
| 13 | } |
| 14 | } |
| 15 | |
| 16 | impl<'de: 'a, 'a> Deserializerust-analyzer cargo serde 1.0.218 de/Deserialize#<'de> for MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#<'a> { |
| 17 | fn deserializerust-analyzer cargo mediatype 0.23.0 serde/impl#[`MediaType<'a>`][`Deserialize<'de>`]deserialize().<D>(deserializer: D) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo mediatype 0.23.0 serde/impl#[`MediaType<'a>`][`Deserialize<'de>`], D::Errorrust-analyzer cargo serde 1.0.218 de/Deserializer#Error#> |
| 18 | where |
| 19 | D: Deserializerrust-analyzer cargo serde 1.0.218 de/Deserializer#<'de>, |
| 20 | { |
| 21 | use serderust-analyzer cargo serde 1.0.218 crate/::derust-analyzer cargo serde 1.0.218 de/::Errorrust-analyzer cargo serde 1.0.218 de/Error#; |
| 22 | let s: &str = Deserializerust-analyzer cargo serde 1.0.218 de/Deserialize#::deserializerust-analyzer cargo serde 1.0.218 de/impls/impl#[`&'a str`][`Deserialize<'de>`]deserialize().(deserializer)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 23 | MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#::parserust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`]parse().(s).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(Errorrust-analyzer cargo serde 1.0.218 de/Error#::customrust-analyzer cargo serde 1.0.218 de/Error#custom().) |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | impl Serializerust-analyzer cargo serde 1.0.218 ser/Serialize# for MediaTypeBufrust-analyzer cargo mediatype 0.23.0 media_type_buf/MediaTypeBuf# { |
| 28 | fn serializerust-analyzer cargo mediatype 0.23.0 serde/impl#[MediaTypeBuf][Serialize]serialize().<S>(&self, serializer: S) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<S::Okrust-analyzer cargo serde 1.0.218 ser/Serializer#Ok#, S::Errorrust-analyzer cargo serde 1.0.218 ser/Serializer#Error#> |
| 29 | where |
| 30 | S: Serializerrust-analyzer cargo serde 1.0.218 ser/Serializer#, |
| 31 | { |
| 32 | self.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().serializerust-analyzer cargo serde 1.0.218 ser/impls/impl#[String][Serialize]serialize().(serializer) |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | impl<'de> Deserializerust-analyzer cargo serde 1.0.218 de/Deserialize#<'de> for MediaTypeBufrust-analyzer cargo mediatype 0.23.0 media_type_buf/MediaTypeBuf# { |
| 37 | fn deserializerust-analyzer cargo mediatype 0.23.0 serde/impl#[MediaTypeBuf][`Deserialize<'de>`]deserialize().<D>(deserializer: D) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo mediatype 0.23.0 serde/impl#[MediaTypeBuf][`Deserialize<'de>`], D::Errorrust-analyzer cargo serde 1.0.218 de/Deserializer#Error#> |
| 38 | where |
| 39 | D: Deserializerrust-analyzer cargo serde 1.0.218 de/Deserializer#<'de>, |
| 40 | { |
| 41 | use serderust-analyzer cargo serde 1.0.218 crate/::derust-analyzer cargo serde 1.0.218 de/::Errorrust-analyzer cargo serde 1.0.218 de/Error#; |
| 42 | let s: Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<str> = Deserializerust-analyzer cargo serde 1.0.218 de/Deserialize#::deserializerust-analyzer cargo serde 1.0.218 de/impls/impl#[`Cow<'a, T>`][`Deserialize<'de>`]deserialize().(deserializer)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 43 | Selfrust-analyzer cargo mediatype 0.23.0 serde/impl#[MediaTypeBuf][`Deserialize<'de>`]::from_stringrust-analyzer cargo mediatype 0.23.0 media_type_buf/impl#[MediaTypeBuf]from_string().(s.into_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, B>`]into_owned().()).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(Errorrust-analyzer cargo serde 1.0.218 de/Error#::customrust-analyzer cargo serde 1.0.218 de/Error#custom().) |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | #[cfg(test)] |
| 48 | mod testsrust-analyzer cargo mediatype 0.23.0 serde/tests/ { |
| 49 | use superrust-analyzer cargo mediatype 0.23.0 serde/::*; |
| 50 | use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#; |
| 51 | use serde_jsonrust-analyzer cargo serde_json 1.0.139 crate/::Valuerust-analyzer cargo serde_json 1.0.139 value/Value#; |
| 52 | |
| 53 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 54 | fn serderust-analyzer cargo mediatype 0.23.0 serde/tests/serde().() { |
| 55 | let original = MediaTypeBufrust-analyzer cargo mediatype 0.23.0 media_type_buf/MediaTypeBuf#::from_strrust-analyzer cargo mediatype 0.23.0 media_type_buf/impl#[MediaTypeBuf][FromStr]from_str().("image/svg+xml; charset=UTF-8;").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 56 | let json = serde_jsonrust-analyzer cargo serde_json 1.0.139 crate/::to_stringrust-analyzer cargo serde_json 1.0.139 ser/to_string().(&original).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 57 | let decoded: MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType# = serde_jsonrust-analyzer cargo serde_json 1.0.139 crate/::from_strrust-analyzer cargo serde_json 1.0.139 de/from_str().(&json).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 58 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(original, decoded); |
| 59 | } |
| 60 | |
| 61 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 62 | fn serde_from_valuerust-analyzer cargo mediatype 0.23.0 serde/tests/serde_from_value().() { |
| 63 | let original = MediaTypeBufrust-analyzer cargo mediatype 0.23.0 media_type_buf/MediaTypeBuf#::from_strrust-analyzer cargo mediatype 0.23.0 media_type_buf/impl#[MediaTypeBuf][FromStr]from_str().("image/svg+xml; charset=UTF-8;").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 64 | let value = Valuerust-analyzer cargo serde_json 1.0.139 value/Value#::Stringrust-analyzer cargo serde_json 1.0.139 value/Value#String#(original.as_strrust-analyzer cargo mediatype 0.23.0 media_type_buf/impl#[MediaTypeBuf]as_str().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 65 | let decoded: MediaTypeBufrust-analyzer cargo mediatype 0.23.0 media_type_buf/MediaTypeBuf# = serde_jsonrust-analyzer cargo serde_json 1.0.139 crate/::from_valuerust-analyzer cargo serde_json 1.0.139 value/from_value().(value).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 66 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(original, decoded); |
| 67 | } |
| 68 | } |