| 1 | use craterust-analyzer cargo bendy 0.6.1 crate/::serderust-analyzer cargo bendy 0.6.1 serde/::commonrust-analyzer cargo bendy 0.6.1 serde/common/::*; |
| 2 | |
| 3 | /// Bencode sub-serializer for maps. |
| 4 | pub struct MapSerializerrust-analyzer cargo bendy 0.6.1 serde/ser/map_serializer/MapSerializer#<'outer> { |
| 5 | pub(craterust-analyzer cargo bendy 0.6.1 crate/) outerrust-analyzer cargo bendy 0.6.1 serde/ser/map_serializer/MapSerializer#outer.: &'outer mut Encoderrust-analyzer cargo bendy 0.6.1 encoding/encoder/Encoder#, |
| 6 | encoderrust-analyzer cargo bendy 0.6.1 serde/ser/map_serializer/MapSerializer#encoder.: UnsortedDictEncoderrust-analyzer cargo bendy 0.6.1 encoding/encoder/UnsortedDictEncoder#, |
| 7 | keyrust-analyzer cargo bendy 0.6.1 serde/ser/map_serializer/MapSerializer#key.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>>, |
| 8 | } |
| 9 | |
| 10 | impl<'outer> MapSerializerrust-analyzer cargo bendy 0.6.1 serde/ser/map_serializer/MapSerializer#<'outer> { |
| 11 | pub(craterust-analyzer cargo bendy 0.6.1 crate/) fn newrust-analyzer cargo bendy 0.6.1 serde/ser/map_serializer/impl#[`MapSerializer<'outer>`]new().( |
| 12 | outer: &'outer mut Encoderrust-analyzer cargo bendy 0.6.1 encoding/encoder/Encoder#, |
| 13 | encoder: UnsortedDictEncoderrust-analyzer cargo bendy 0.6.1 encoding/encoder/UnsortedDictEncoder#, |
| 14 | ) -> MapSerializerrust-analyzer cargo bendy 0.6.1 serde/ser/map_serializer/MapSerializer#<'outer> { |
| 15 | MapSerializerrust-analyzer cargo bendy 0.6.1 serde/ser/map_serializer/MapSerializer# { |
| 16 | encoderrust-analyzer cargo bendy 0.6.1 serde/ser/map_serializer/MapSerializer#encoder., |
| 17 | outerrust-analyzer cargo bendy 0.6.1 serde/ser/map_serializer/MapSerializer#outer., |
| 18 | keyrust-analyzer cargo bendy 0.6.1 serde/ser/map_serializer/MapSerializer#key.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | fn serializerust-analyzer cargo bendy 0.6.1 serde/ser/map_serializer/impl#[`MapSerializer<'outer>`]serialize().<T>(&self, value: &T) -> Resultrust-analyzer cargo bendy 0.6.1 serde/error/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>> |
| 23 | where |
| 24 | T: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# + Serializerust-analyzer cargo serde 1.0.140 ser/Serialize#, |
| 25 | { |
| 26 | let mut serializer = Serializerrust-analyzer cargo bendy 0.6.1 serde/ser/Serializer#::with_max_depthrust-analyzer cargo bendy 0.6.1 serde/ser/impl#[Serializer]with_max_depth().(self.encoderrust-analyzer cargo bendy 0.6.1 serde/ser/map_serializer/MapSerializer#encoder..remaining_depthrust-analyzer cargo bendy 0.6.1 encoding/encoder/impl#[UnsortedDictEncoder]remaining_depth().()); |
| 27 | value.serializerust-analyzer cargo serde 1.0.140 ser/Serialize#serialize().(&mut serializer)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 28 | serializer.into_bytesrust-analyzer cargo bendy 0.6.1 serde/ser/impl#[Serializer]into_bytes().() |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | impl<'outer> SerializeMaprust-analyzer cargo serde 1.0.140 ser/SerializeMap# for MapSerializerrust-analyzer cargo bendy 0.6.1 serde/ser/map_serializer/MapSerializer#<'outer> { |
| 33 | type Errorrust-analyzer cargo bendy 0.6.1 serde/ser/map_serializer/impl#[`MapSerializer<'outer>`][SerializeMap]Error# = Errorrust-analyzer cargo bendy 0.6.1 serde/error/Error#; |
| 34 | type Okrust-analyzer cargo bendy 0.6.1 serde/ser/map_serializer/impl#[`MapSerializer<'outer>`][SerializeMap]Ok# = (); |
| 35 | |
| 36 | fn serialize_keyrust-analyzer cargo bendy 0.6.1 serde/ser/map_serializer/impl#[`MapSerializer<'outer>`][SerializeMap]serialize_key().<T>(&mut self, key: &T) -> Resultrust-analyzer cargo bendy 0.6.1 serde/error/Result#<()> |
| 37 | where |
| 38 | T: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# + Serializerust-analyzer cargo serde 1.0.140 ser/Serialize#, |
| 39 | { |
| 40 | if self.keyrust-analyzer cargo bendy 0.6.1 serde/ser/map_serializer/MapSerializer#key..is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() { |
| 41 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo bendy 0.6.1 serde/error/Error#::MapSerializationCallOrderrust-analyzer cargo bendy 0.6.1 serde/error/Error#MapSerializationCallOrder#); |
| 42 | } |
| 43 | |
| 44 | let mut encoded = self.serializerust-analyzer cargo bendy 0.6.1 serde/ser/map_serializer/impl#[`MapSerializer<'outer>`]serialize().(key)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 45 | |
| 46 | match encoded.firstrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]first().() { |
| 47 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(b'0'..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#b'9') => {}, |
| 48 | _ => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo bendy 0.6.1 serde/error/Error#::ArbitraryMapKeysUnsupportedrust-analyzer cargo bendy 0.6.1 serde/error/Error#ArbitraryMapKeysUnsupported#), |
| 49 | } |
| 50 | |
| 51 | let colon = encoded.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().positionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]position().(|b| *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().b rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b':').unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 52 | encoded.drainrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]drain().(0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#colon rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1); |
| 53 | |
| 54 | self.keyrust-analyzer cargo bendy 0.6.1 serde/ser/map_serializer/MapSerializer#key. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(encoded); |
| 55 | |
| 56 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 57 | } |
| 58 | |
| 59 | fn serialize_valuerust-analyzer cargo bendy 0.6.1 serde/ser/map_serializer/impl#[`MapSerializer<'outer>`][SerializeMap]serialize_value().<T>(&mut self, value: &T) -> Resultrust-analyzer cargo bendy 0.6.1 serde/error/Result#<()> |
| 60 | where |
| 61 | T: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# + Serializerust-analyzer cargo serde 1.0.140 ser/Serialize#, |
| 62 | { |
| 63 | match self.keyrust-analyzer cargo bendy 0.6.1 serde/ser/map_serializer/MapSerializer#key..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().() { |
| 64 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(bytes) => { |
| 65 | let encoded = self.serializerust-analyzer cargo bendy 0.6.1 serde/ser/map_serializer/impl#[`MapSerializer<'outer>`]serialize().(value)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 66 | self.encoderrust-analyzer cargo bendy 0.6.1 serde/ser/map_serializer/MapSerializer#encoder..save_pairrust-analyzer cargo bendy 0.6.1 encoding/encoder/impl#[UnsortedDictEncoder]save_pair().(&bytes, encoded)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 67 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 68 | }, |
| 69 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo bendy 0.6.1 serde/error/Error#::MapSerializationCallOrderrust-analyzer cargo bendy 0.6.1 serde/error/Error#MapSerializationCallOrder#), |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | fn endrust-analyzer cargo bendy 0.6.1 serde/ser/map_serializer/impl#[`MapSerializer<'outer>`][SerializeMap]end().(self) -> Resultrust-analyzer cargo bendy 0.6.1 serde/error/Result#<()> { |
| 74 | if self.keyrust-analyzer cargo bendy 0.6.1 serde/ser/map_serializer/MapSerializer#key..is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() { |
| 75 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo bendy 0.6.1 serde/error/Error#::MapSerializationCallOrderrust-analyzer cargo bendy 0.6.1 serde/error/Error#MapSerializationCallOrder#); |
| 76 | } |
| 77 | self.outerrust-analyzer cargo bendy 0.6.1 serde/ser/map_serializer/MapSerializer#outer..end_unsorted_dictrust-analyzer cargo bendy 0.6.1 encoding/encoder/impl#[Encoder]end_unsorted_dict().(self.encoderrust-analyzer cargo bendy 0.6.1 serde/ser/map_serializer/MapSerializer#encoder.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 78 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 79 | } |
| 80 | } |