| 1 | //! `Value`s hold arbitrary borrowed or owneed bencode data. Unlike `Objects`, |
| 2 | //! they can be cloned and traversed multiple times. |
| 3 | //! |
| 4 | //! `Value` implements `FromBencode`, `ToBencode`. If the `serde` feature is |
| 5 | //! enabled, it also implements `Serialize` and `Deserialize`. |
| 6 | |
| 7 | use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::{ |
| 8 | 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#, ToOwnedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/ToOwned#}, |
| 9 | collectionsrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/::BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#, |
| 10 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/::Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#, |
| 11 | }; |
| 12 | |
| 13 | #[cfg(feature = "serde")] |
| 14 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{ |
| 15 | convertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/::TryIntorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryInto#, |
| 16 | fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::{selfrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/, Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#}, |
| 17 | markerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/::PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#, |
| 18 | }; |
| 19 | |
| 20 | #[cfg(feature = "serde")] |
| 21 | use serde_rust-analyzer cargo serde 1.0.140 crate/ as serderust-analyzer cargo serde 1.0.140 crate/; |
| 22 | |
| 23 | #[cfg(feature = "serde")] |
| 24 | use serderust-analyzer cargo serde 1.0.140 crate/::{ |
| 25 | Serializerust-analyzer cargo serde 1.0.140 ser/Serialize#, |
| 26 | serrust-analyzer cargo serde 1.0.140 ser/::{SerializeMaprust-analyzer cargo serde 1.0.140 ser/SerializeMap#, SerializeSeqrust-analyzer cargo serde 1.0.140 ser/SerializeSeq#}, |
| 27 | }; |
| 28 | |
| 29 | use craterust-analyzer cargo bendy 0.6.1 crate/::{ |
| 30 | decodingrust-analyzer cargo bendy 0.6.1 decoding/::{FromBencoderust-analyzer cargo bendy 0.6.1 decoding/from_bencode/FromBencode#, Objectrust-analyzer cargo bendy 0.6.1 decoding/object/Object#}, |
| 31 | encodingrust-analyzer cargo bendy 0.6.1 encoding/::{SingleItemEncoderrust-analyzer cargo bendy 0.6.1 encoding/encoder/SingleItemEncoder#, ToBencoderust-analyzer cargo bendy 0.6.1 encoding/to_bencode/ToBencode#}, |
| 32 | }; |
| 33 | |
| 34 | /// An owned or borrowed bencoded value. |
| 35 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 36 | pub enum Valuerust-analyzer cargo bendy 0.6.1 value/Value#<'a> { |
| 37 | /// An owned or borrowed byte string |
| 38 | Bytesrust-analyzer cargo bendy 0.6.1 value/Value#Bytes#(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'a, [u8]>), |
| 39 | /// A dictionary mapping byte strings to values |
| 40 | Dictrust-analyzer cargo bendy 0.6.1 value/Value#Dict#(BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#<Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'a, [u8]>, Valuerust-analyzer cargo bendy 0.6.1 value/Value#<'a>>), |
| 41 | /// A signed integer |
| 42 | Integerrust-analyzer cargo bendy 0.6.1 value/Value#Integer#(i64), |
| 43 | /// A list of values |
| 44 | Listrust-analyzer cargo bendy 0.6.1 value/Value#List#(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Valuerust-analyzer cargo bendy 0.6.1 value/Value#<'a>>), |
| 45 | } |
| 46 | |
| 47 | impl<'a> Valuerust-analyzer cargo bendy 0.6.1 value/Value#<'a> { |
| 48 | /// Convert this Value into an owned Value with static lifetime |
| 49 | pub fn into_ownedrust-analyzer cargo bendy 0.6.1 value/impl#[`Value<'a>`]into_owned().(self) -> Valuerust-analyzer cargo bendy 0.6.1 value/Value#<'static> { |
| 50 | match self { |
| 51 | Valuerust-analyzer cargo bendy 0.6.1 value/Value#::Bytesrust-analyzer cargo bendy 0.6.1 value/Value#Bytes#(bytes) => Valuerust-analyzer cargo bendy 0.6.1 value/Value#::Bytesrust-analyzer cargo bendy 0.6.1 value/Value#Bytes#(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(bytes.into_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, B>`]into_owned().())), |
| 52 | Valuerust-analyzer cargo bendy 0.6.1 value/Value#::Dictrust-analyzer cargo bendy 0.6.1 value/Value#Dict#(dict) => Valuerust-analyzer cargo bendy 0.6.1 value/Value#::Dictrust-analyzer cargo bendy 0.6.1 value/Value#Dict#( |
| 53 | dict.into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`][IntoIterator]into_iter().() |
| 54 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(key, value)| (Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(key.into_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, B>`]into_owned().()), value.into_ownedrust-analyzer cargo bendy 0.6.1 value/impl#[`Value<'a>`]into_owned().())) |
| 55 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(), |
| 56 | ), |
| 57 | Valuerust-analyzer cargo bendy 0.6.1 value/Value#::Integerrust-analyzer cargo bendy 0.6.1 value/Value#Integer#(integer) => Valuerust-analyzer cargo bendy 0.6.1 value/Value#::Integerrust-analyzer cargo bendy 0.6.1 value/Value#Integer#(integer), |
| 58 | Valuerust-analyzer cargo bendy 0.6.1 value/Value#::Listrust-analyzer cargo bendy 0.6.1 value/Value#List#(list) => Valuerust-analyzer cargo bendy 0.6.1 value/Value#::Listrust-analyzer cargo bendy 0.6.1 value/Value#List#(list.into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(Valuerust-analyzer cargo bendy 0.6.1 value/Value#::into_ownedrust-analyzer cargo bendy 0.6.1 value/impl#[`Value<'a>`]into_owned().).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().()), |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | impl<'a> ToBencoderust-analyzer cargo bendy 0.6.1 encoding/to_bencode/ToBencode# for Valuerust-analyzer cargo bendy 0.6.1 value/Value#<'a> { |
| 64 | /// This is set to zero to indicate a statically unknown depth. |
| 65 | /// See the [`encoding`][crate::encoding#dynamic-depth] module docs. |
| 66 | const MAX_DEPTHrust-analyzer cargo bendy 0.6.1 value/impl#[`Value<'a>`][ToBencode]MAX_DEPTH.: usize = 0; |
| 67 | |
| 68 | fn encoderust-analyzer cargo bendy 0.6.1 value/impl#[`Value<'a>`][ToBencode]encode().(&self, encoder: SingleItemEncoderrust-analyzer cargo bendy 0.6.1 encoding/encoder/SingleItemEncoder#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), craterust-analyzer cargo bendy 0.6.1 crate/::encodingrust-analyzer cargo bendy 0.6.1 encoding/::Errorrust-analyzer cargo bendy 0.6.1 encoding/error/Error#> { |
| 69 | match self { |
| 70 | Valuerust-analyzer cargo bendy 0.6.1 value/Value#::Bytesrust-analyzer cargo bendy 0.6.1 value/Value#Bytes#(bytes) => encoder.emit_bytesrust-analyzer cargo bendy 0.6.1 encoding/encoder/impl#[`SingleItemEncoder<'a>`]emit_bytes().(bytes), |
| 71 | Valuerust-analyzer cargo bendy 0.6.1 value/Value#::Dictrust-analyzer cargo bendy 0.6.1 value/Value#Dict#(dict) => dict.encoderust-analyzer cargo bendy 0.6.1 encoding/to_bencode/impl#[`BTreeMap<K, V>`][ToBencode]encode().(encoder), |
| 72 | Valuerust-analyzer cargo bendy 0.6.1 value/Value#::Integerrust-analyzer cargo bendy 0.6.1 value/Value#Integer#(integer) => integer.encoderust-analyzer cargo bendy 0.6.1 encoding/to_bencode/impl#[i64][ToBencode]encode().(encoder), |
| 73 | Valuerust-analyzer cargo bendy 0.6.1 value/Value#::Listrust-analyzer cargo bendy 0.6.1 value/Value#List#(list) => list.encoderust-analyzer cargo bendy 0.6.1 encoding/to_bencode/impl#[`Vec<ContentT>`][ToBencode]encode().(encoder), |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | impl<'a> FromBencoderust-analyzer cargo bendy 0.6.1 decoding/from_bencode/FromBencode# for Valuerust-analyzer cargo bendy 0.6.1 value/Value#<'a> { |
| 79 | /// This is set to zero to indicate a statically unknown depth. |
| 80 | /// See the [`encoding`][crate::encoding#dynamic-depth] module docs. |
| 81 | const EXPECTED_RECURSION_DEPTHrust-analyzer cargo bendy 0.6.1 value/impl#[`Value<'a>`][FromBencode]EXPECTED_RECURSION_DEPTH.: usize = <Selfrust-analyzer cargo bendy 0.6.1 value/impl#[`Value<'a>`][FromBencode] as ToBencoderust-analyzer cargo bendy 0.6.1 encoding/to_bencode/ToBencode#>::MAX_DEPTHrust-analyzer cargo bendy 0.6.1 value/impl#[`Value<'a>`][ToBencode]MAX_DEPTH.; |
| 82 | |
| 83 | fn decode_bencode_objectrust-analyzer cargo bendy 0.6.1 value/impl#[`Value<'a>`][FromBencode]decode_bencode_object().(object: Objectrust-analyzer cargo bendy 0.6.1 decoding/object/Object#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo bendy 0.6.1 value/impl#[`Value<'a>`][FromBencode], craterust-analyzer cargo bendy 0.6.1 crate/::decodingrust-analyzer cargo bendy 0.6.1 decoding/::Errorrust-analyzer cargo bendy 0.6.1 decoding/error/Error#> { |
| 84 | match object { |
| 85 | Objectrust-analyzer cargo bendy 0.6.1 decoding/object/Object#::Bytesrust-analyzer cargo bendy 0.6.1 decoding/object/Object#Bytes#(bytes) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Valuerust-analyzer cargo bendy 0.6.1 value/Value#::Bytesrust-analyzer cargo bendy 0.6.1 value/Value#Bytes#(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(bytes.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`][ToOwned]to_owned().()))), |
| 86 | Objectrust-analyzer cargo bendy 0.6.1 decoding/object/Object#::Dictrust-analyzer cargo bendy 0.6.1 decoding/object/Object#Dict#(mut decoder) => { |
| 87 | let mut dict = BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V>`]new().(); |
| 88 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((key, value)) = decoder.next_pairrust-analyzer cargo bendy 0.6.1 decoding/decoder/impl#[`DictDecoder<'obj, 'ser>`]next_pair().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 89 | dict.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]insert().( |
| 90 | Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(key.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`][ToOwned]to_owned().()), |
| 91 | Valuerust-analyzer cargo bendy 0.6.1 value/Value#::decode_bencode_objectrust-analyzer cargo bendy 0.6.1 value/impl#[`Value<'a>`][FromBencode]decode_bencode_object().(value)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 92 | ); |
| 93 | } |
| 94 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Valuerust-analyzer cargo bendy 0.6.1 value/Value#::Dictrust-analyzer cargo bendy 0.6.1 value/Value#Dict#(dict)) |
| 95 | }, |
| 96 | Objectrust-analyzer cargo bendy 0.6.1 decoding/object/Object#::Integerrust-analyzer cargo bendy 0.6.1 decoding/object/Object#Integer#(text) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Valuerust-analyzer cargo bendy 0.6.1 value/Value#::Integerrust-analyzer cargo bendy 0.6.1 value/Value#Integer#(text.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().)), |
| 97 | Objectrust-analyzer cargo bendy 0.6.1 decoding/object/Object#::Listrust-analyzer cargo bendy 0.6.1 decoding/object/Object#List#(mut decoder) => { |
| 98 | let mut list = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(); |
| 99 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(object) = decoder.next_objectrust-analyzer cargo bendy 0.6.1 decoding/decoder/impl#[`ListDecoder<'obj, 'ser>`]next_object().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 100 | list.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Valuerust-analyzer cargo bendy 0.6.1 value/Value#::decode_bencode_objectrust-analyzer cargo bendy 0.6.1 value/impl#[`Value<'a>`][FromBencode]decode_bencode_object().(object)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().); |
| 101 | } |
| 102 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Valuerust-analyzer cargo bendy 0.6.1 value/Value#::Listrust-analyzer cargo bendy 0.6.1 value/Value#List#(list)) |
| 103 | }, |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | #[cfg(feature = "serde")] |
| 109 | mod serde_implsrust-analyzer cargo bendy 0.6.1 value/serde_impls/ { |
| 110 | use superrust-analyzer cargo bendy 0.6.1 value/::*; |
| 111 | |
| 112 | use serde_bytesrust-analyzer cargo serde_bytes 0.11.6 crate/::Bytesrust-analyzer cargo serde_bytes 0.11.6 bytes/Bytes#; |
| 113 | |
| 114 | impl<'a> Serializerust-analyzer cargo serde 1.0.140 ser/Serialize# for Valuerust-analyzer cargo bendy 0.6.1 value/Value#<'a> { |
| 115 | fn serializerust-analyzer cargo bendy 0.6.1 value/serde_impls/impl#[`Value<'a>`][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.140 ser/Serializer#Ok#, S::Errorrust-analyzer cargo serde 1.0.140 ser/Serializer#Error#> |
| 116 | where |
| 117 | S: serderust-analyzer cargo serde 1.0.140 crate/::serrust-analyzer cargo serde 1.0.140 ser/::Serializerrust-analyzer cargo serde 1.0.140 ser/Serializer#, |
| 118 | { |
| 119 | match self { |
| 120 | Valuerust-analyzer cargo bendy 0.6.1 value/Value#::Bytesrust-analyzer cargo bendy 0.6.1 value/Value#Bytes#(string) => serializer.serialize_bytesrust-analyzer cargo serde 1.0.140 ser/Serializer#serialize_bytes().(string), |
| 121 | Valuerust-analyzer cargo bendy 0.6.1 value/Value#::Integerrust-analyzer cargo bendy 0.6.1 value/Value#Integer#(int) => serializer.serialize_i64rust-analyzer cargo serde 1.0.140 ser/Serializer#serialize_i64().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().int), |
| 122 | Valuerust-analyzer cargo bendy 0.6.1 value/Value#::Listrust-analyzer cargo bendy 0.6.1 value/Value#List#(list) => { |
| 123 | let mut seed = serializer.serialize_seqrust-analyzer cargo serde 1.0.140 ser/Serializer#serialize_seq().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(list.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 124 | for value in list { |
| 125 | seed.serialize_elementrust-analyzer cargo serde 1.0.140 ser/SerializeSeq#serialize_element().(value)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 126 | } |
| 127 | seed.endrust-analyzer cargo serde 1.0.140 ser/SerializeSeq#end().() |
| 128 | }, |
| 129 | Valuerust-analyzer cargo bendy 0.6.1 value/Value#::Dictrust-analyzer cargo bendy 0.6.1 value/Value#Dict#(dict) => { |
| 130 | let mut seed = serializer.serialize_maprust-analyzer cargo serde 1.0.140 ser/Serializer#serialize_map().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(dict.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]len().()))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 131 | for (k, v) in dict { |
| 132 | let bytes = Bytesrust-analyzer cargo serde_bytes 0.11.6 bytes/Bytes#::newrust-analyzer cargo serde_bytes 0.11.6 bytes/impl#[Bytes]new().(k); |
| 133 | seed.serialize_entryrust-analyzer cargo serde 1.0.140 ser/SerializeMap#serialize_entry().(bytes, v)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 134 | } |
| 135 | seed.endrust-analyzer cargo serde 1.0.140 ser/SerializeMap#end().() |
| 136 | }, |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | impl<'de: 'a, 'a> serderust-analyzer cargo serde 1.0.140 crate/::derust-analyzer cargo serde 1.0.140 de/::Deserializerust-analyzer cargo serde 1.0.140 de/Deserialize#<'de> for Valuerust-analyzer cargo bendy 0.6.1 value/Value#<'a> { |
| 142 | #[inline] |
| 143 | fn deserializerust-analyzer cargo bendy 0.6.1 value/serde_impls/impl#[`Value<'a>`][`Deserialize<'de>`]deserialize().<D>(deserializer: D) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Valuerust-analyzer cargo bendy 0.6.1 value/Value#<'a>, D::Errorrust-analyzer cargo serde 1.0.140 de/Deserializer#Error#> |
| 144 | where |
| 145 | D: serderust-analyzer cargo serde 1.0.140 crate/::derust-analyzer cargo serde 1.0.140 de/::Deserializerrust-analyzer cargo serde 1.0.140 de/Deserializer#<'de>, |
| 146 | { |
| 147 | deserializer.deserialize_anyrust-analyzer cargo serde 1.0.140 de/Deserializer#deserialize_any().(Visitorrust-analyzer cargo bendy 0.6.1 value/serde_impls/Visitor#(PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#)) |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | struct Visitorrust-analyzer cargo bendy 0.6.1 value/serde_impls/Visitor#<'a>(PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#<&'a ()>); |
| 152 | |
| 153 | impl<'de: 'a, 'a> serderust-analyzer cargo serde 1.0.140 crate/::derust-analyzer cargo serde 1.0.140 de/::Visitorrust-analyzer cargo serde 1.0.140 de/Visitor#<'de> for Visitorrust-analyzer cargo bendy 0.6.1 value/serde_impls/Visitor#<'a> { |
| 154 | type Valuerust-analyzer cargo bendy 0.6.1 value/serde_impls/impl#[`Visitor<'a>`][`Visitor<'de>`]Value# = Valuerust-analyzer cargo bendy 0.6.1 value/Value#<'a>; |
| 155 | |
| 156 | fn expectingrust-analyzer cargo bendy 0.6.1 value/serde_impls/impl#[`Visitor<'a>`][`Visitor<'de>`]expecting().(&self, formatter: &mut Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 157 | formatter.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("any valid BEncode value") |
| 158 | } |
| 159 | |
| 160 | fn visit_i64rust-analyzer cargo bendy 0.6.1 value/serde_impls/impl#[`Visitor<'a>`][`Visitor<'de>`]visit_i64().<E>(self, value: i64) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Valuerust-analyzer cargo bendy 0.6.1 value/Value#<'a>, E> { |
| 161 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Valuerust-analyzer cargo bendy 0.6.1 value/Value#::Integerrust-analyzer cargo bendy 0.6.1 value/Value#Integer#(value)) |
| 162 | } |
| 163 | |
| 164 | fn visit_u64rust-analyzer cargo bendy 0.6.1 value/serde_impls/impl#[`Visitor<'a>`][`Visitor<'de>`]visit_u64().<E>(self, value: u64) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Valuerust-analyzer cargo bendy 0.6.1 value/Value#<'a>, E> { |
| 165 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Valuerust-analyzer cargo bendy 0.6.1 value/Value#::Integerrust-analyzer cargo bendy 0.6.1 value/Value#Integer#(value.try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryInto<U>`]try_into().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().())) |
| 166 | } |
| 167 | |
| 168 | fn visit_borrowed_bytesrust-analyzer cargo bendy 0.6.1 value/serde_impls/impl#[`Visitor<'a>`][`Visitor<'de>`]visit_borrowed_bytes().<E>(self, value: &'de [u8]) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Valuerust-analyzer cargo bendy 0.6.1 value/Value#<'a>, E> |
| 169 | where |
| 170 | E: serderust-analyzer cargo serde 1.0.140 crate/::derust-analyzer cargo serde 1.0.140 de/::Errorrust-analyzer cargo serde 1.0.140 de/Error#, |
| 171 | { |
| 172 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Valuerust-analyzer cargo bendy 0.6.1 value/Value#::Bytesrust-analyzer cargo bendy 0.6.1 value/Value#Bytes#(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(value))) |
| 173 | } |
| 174 | |
| 175 | fn visit_borrowed_strrust-analyzer cargo bendy 0.6.1 value/serde_impls/impl#[`Visitor<'a>`][`Visitor<'de>`]visit_borrowed_str().<E>(self, value: &'de str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Valuerust-analyzer cargo bendy 0.6.1 value/Value#<'a>, E> |
| 176 | where |
| 177 | E: serderust-analyzer cargo serde 1.0.140 crate/::derust-analyzer cargo serde 1.0.140 de/::Errorrust-analyzer cargo serde 1.0.140 de/Error#, |
| 178 | { |
| 179 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Valuerust-analyzer cargo bendy 0.6.1 value/Value#::Bytesrust-analyzer cargo bendy 0.6.1 value/Value#Bytes#(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(value.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()))) |
| 180 | } |
| 181 | |
| 182 | fn visit_strrust-analyzer cargo bendy 0.6.1 value/serde_impls/impl#[`Visitor<'a>`][`Visitor<'de>`]visit_str().<E>(self, value: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Valuerust-analyzer cargo bendy 0.6.1 value/Value#<'a>, E> |
| 183 | where |
| 184 | E: serderust-analyzer cargo serde 1.0.140 crate/::derust-analyzer cargo serde 1.0.140 de/::Errorrust-analyzer cargo serde 1.0.140 de/Error#, |
| 185 | { |
| 186 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Valuerust-analyzer cargo bendy 0.6.1 value/Value#::Bytesrust-analyzer cargo bendy 0.6.1 value/Value#Bytes#(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(value.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().().to_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]to_vec().()))) |
| 187 | } |
| 188 | |
| 189 | fn visit_stringrust-analyzer cargo bendy 0.6.1 value/serde_impls/impl#[`Visitor<'a>`][`Visitor<'de>`]visit_string().<E>(self, value: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Valuerust-analyzer cargo bendy 0.6.1 value/Value#<'a>, E> { |
| 190 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Valuerust-analyzer cargo bendy 0.6.1 value/Value#::Bytesrust-analyzer cargo bendy 0.6.1 value/Value#Bytes#(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(value.into_bytesrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]into_bytes().()))) |
| 191 | } |
| 192 | |
| 193 | fn visit_byte_bufrust-analyzer cargo bendy 0.6.1 value/serde_impls/impl#[`Visitor<'a>`][`Visitor<'de>`]visit_byte_buf().<E>(self, value: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Valuerust-analyzer cargo bendy 0.6.1 value/Value#<'a>, E> { |
| 194 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Valuerust-analyzer cargo bendy 0.6.1 value/Value#::Bytesrust-analyzer cargo bendy 0.6.1 value/Value#Bytes#(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(value))) |
| 195 | } |
| 196 | |
| 197 | fn visit_seqrust-analyzer cargo bendy 0.6.1 value/serde_impls/impl#[`Visitor<'a>`][`Visitor<'de>`]visit_seq().<V>(self, mut access: V) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Valuerust-analyzer cargo bendy 0.6.1 value/Value#<'a>, V::Errorrust-analyzer cargo serde 1.0.140 de/SeqAccess#Error#> |
| 198 | where |
| 199 | V: serderust-analyzer cargo serde 1.0.140 crate/::derust-analyzer cargo serde 1.0.140 de/::SeqAccessrust-analyzer cargo serde 1.0.140 de/SeqAccess#<'de>, |
| 200 | { |
| 201 | let mut list = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(); |
| 202 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(e) = access.next_elementrust-analyzer cargo serde 1.0.140 de/SeqAccess#next_element().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 203 | list.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(e); |
| 204 | } |
| 205 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Valuerust-analyzer cargo bendy 0.6.1 value/Value#::Listrust-analyzer cargo bendy 0.6.1 value/Value#List#(list)) |
| 206 | } |
| 207 | |
| 208 | fn visit_maprust-analyzer cargo bendy 0.6.1 value/serde_impls/impl#[`Visitor<'a>`][`Visitor<'de>`]visit_map().<V>(self, mut access: V) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Valuerust-analyzer cargo bendy 0.6.1 value/Value#<'a>, V::Errorrust-analyzer cargo serde 1.0.140 de/MapAccess#Error#> |
| 209 | where |
| 210 | V: serderust-analyzer cargo serde 1.0.140 crate/::derust-analyzer cargo serde 1.0.140 de/::MapAccessrust-analyzer cargo serde 1.0.140 de/MapAccess#<'de>, |
| 211 | { |
| 212 | let mut map = BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V>`]new().(); |
| 213 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((k, v)) = access.next_entryrust-analyzer cargo serde 1.0.140 de/MapAccess#next_entry().::<&Bytesrust-analyzer cargo serde_bytes 0.11.6 bytes/Bytes#, _>()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 214 | map.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]insert().(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(k.as_refrust-analyzer cargo serde_bytes 0.11.6 bytes/impl#[Bytes][`AsRef<[u8]>`]as_ref().()), v); |
| 215 | } |
| 216 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Valuerust-analyzer cargo bendy 0.6.1 value/Value#::Dictrust-analyzer cargo bendy 0.6.1 value/Value#Dict#(map)) |
| 217 | } |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | #[cfg(test)] |
| 222 | mod testsrust-analyzer cargo bendy 0.6.1 value/tests/ { |
| 223 | use craterust-analyzer cargo bendy 0.6.1 crate/::{decodingrust-analyzer cargo bendy 0.6.1 decoding/::Decoderrust-analyzer cargo bendy 0.6.1 decoding/decoder/Decoder#, encodingrust-analyzer cargo bendy 0.6.1 encoding/::Encoderrust-analyzer cargo bendy 0.6.1 encoding/encoder/Encoder#}; |
| 224 | |
| 225 | use superrust-analyzer cargo bendy 0.6.1 value/::*; |
| 226 | |
| 227 | use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::{stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/::Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/}; |
| 228 | |
| 229 | /// Round-trip and verify encoding. Uses depth 0. |
| 230 | fn caserust-analyzer cargo bendy 0.6.1 value/tests/case().(value: Valuerust-analyzer cargo bendy 0.6.1 value/Value#, expected: impl AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<[u8]>) { |
| 231 | case_implrust-analyzer cargo bendy 0.6.1 value/tests/case_impl().(value, 0, expected); |
| 232 | } |
| 233 | |
| 234 | fn case_implrust-analyzer cargo bendy 0.6.1 value/tests/case_impl().(value: Valuerust-analyzer cargo bendy 0.6.1 value/Value#, depth: usize, expected: impl AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<[u8]>) { |
| 235 | let expected = expected.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().(); |
| 236 | |
| 237 | let mut encoder = Encoderrust-analyzer cargo bendy 0.6.1 encoding/encoder/Encoder#::newrust-analyzer cargo bendy 0.6.1 encoding/encoder/impl#[Encoder]new().().with_max_depthrust-analyzer cargo bendy 0.6.1 encoding/encoder/impl#[Encoder]with_max_depth().(depth); |
| 238 | |
| 239 | match encoder.emitrust-analyzer cargo bendy 0.6.1 encoding/encoder/impl#[Encoder]emit().(&value) { |
| 240 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Failed to encode `{:?}`: {}", value, err), |
| 241 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) => (), |
| 242 | }; |
| 243 | |
| 244 | let encoded = match encoder.get_outputrust-analyzer cargo bendy 0.6.1 encoding/encoder/impl#[Encoder]get_output().() { |
| 245 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(bytes) => bytes, |
| 246 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Failed to encode `{:?}`: {}", value, err), |
| 247 | }; |
| 248 | |
| 249 | if encoded rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/partial_eq/impl#[`Vec<T, A>`][`PartialEq<&[U]>`]ne().!=rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/partial_eq/impl#[`Vec<T, A>`][`PartialEq<&[U]>`]ne(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/partial_eq/impl#[`Vec<T, A>`][`PartialEq<&[U]>`]ne().expected { |
| 250 | panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!( |
| 251 | "Expected `{:?}` to encode as `{}`, but got `{}", |
| 252 | value, |
| 253 | Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::from_utf8_lossyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]from_utf8_lossy().(expected), |
| 254 | Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::from_utf8_lossyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]from_utf8_lossy().(&encoded) |
| 255 | ) |
| 256 | } |
| 257 | |
| 258 | let mut decoder = Decoderrust-analyzer cargo bendy 0.6.1 decoding/decoder/Decoder#::newrust-analyzer cargo bendy 0.6.1 decoding/decoder/impl#[`Decoder<'ser>`]new().(&encoded).with_max_depthrust-analyzer cargo bendy 0.6.1 decoding/decoder/impl#[`Decoder<'ser>`]with_max_depth().(depth); |
| 259 | let object = match decoder.next_objectrust-analyzer cargo bendy 0.6.1 decoding/decoder/impl#[`Decoder<'ser>`]next_object().() { |
| 260 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(obj)) => obj, |
| 261 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!( |
| 262 | "Failed to decode value from `{}`: Unexpected EOF.", |
| 263 | Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::from_utf8_lossyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]from_utf8_lossy().(&encoded), |
| 264 | ), |
| 265 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!( |
| 266 | "Failed to decode value from `{}`: {}", |
| 267 | Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::from_utf8_lossyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]from_utf8_lossy().(&encoded), |
| 268 | err, |
| 269 | ), |
| 270 | }; |
| 271 | let decoded = match Valuerust-analyzer cargo bendy 0.6.1 value/Value#::decode_bencode_objectrust-analyzer cargo bendy 0.6.1 value/impl#[`Value<'a>`][FromBencode]decode_bencode_object().(object) { |
| 272 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(decoded) => decoded, |
| 273 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!( |
| 274 | "Failed to decode value from `{}`: {}", |
| 275 | Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::from_utf8_lossyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]from_utf8_lossy().(&encoded), |
| 276 | err, |
| 277 | ), |
| 278 | }; |
| 279 | |
| 280 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(decoded, value); |
| 281 | |
| 282 | #[cfg(feature = "serde")] |
| 283 | { |
| 284 | let deserialized = match craterust-analyzer cargo bendy 0.6.1 crate/::serderust-analyzer cargo bendy 0.6.1 serde/::derust-analyzer cargo bendy 0.6.1 serde/de/::from_bytesrust-analyzer cargo bendy 0.6.1 serde/de/from_bytes().::<Valuerust-analyzer cargo bendy 0.6.1 value/Value#>(expected) { |
| 285 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(deserialized) => deserialized, |
| 286 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!( |
| 287 | "Failed to deserialize value from `{}`: {}", |
| 288 | Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::from_utf8_lossyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]from_utf8_lossy().(&expected), |
| 289 | err |
| 290 | ), |
| 291 | }; |
| 292 | |
| 293 | if deserialized rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().value { |
| 294 | panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!( |
| 295 | "Deserialize Serialize produced unexpected value: `{:?}` != `{:?}`", |
| 296 | deserialized, value |
| 297 | ); |
| 298 | } |
| 299 | |
| 300 | let serialized = match craterust-analyzer cargo bendy 0.6.1 crate/::serderust-analyzer cargo bendy 0.6.1 serde/::serrust-analyzer cargo bendy 0.6.1 serde/ser/::to_bytesrust-analyzer cargo bendy 0.6.1 serde/ser/to_bytes().(&value) { |
| 301 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(serialized) => serialized, |
| 302 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Failed to serialize `{:?}`: {}", value, err), |
| 303 | }; |
| 304 | |
| 305 | if serialized rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/partial_eq/impl#[`Vec<T, A>`][`PartialEq<&[U]>`]ne().!=rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/partial_eq/impl#[`Vec<T, A>`][`PartialEq<&[U]>`]ne(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/partial_eq/impl#[`Vec<T, A>`][`PartialEq<&[U]>`]ne().expected { |
| 306 | panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!( |
| 307 | "Serialize Serialize produced unexpected bencode: `{:?}` != `{:?}`", |
| 308 | Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::from_utf8_lossyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]from_utf8_lossy().(&serialized), |
| 309 | Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::from_utf8_lossyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]from_utf8_lossy().(expected) |
| 310 | ); |
| 311 | } |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 316 | fn bytesrust-analyzer cargo bendy 0.6.1 value/tests/bytes().() { |
| 317 | caserust-analyzer cargo bendy 0.6.1 value/tests/case().(Valuerust-analyzer cargo bendy 0.6.1 value/Value#::Bytesrust-analyzer cargo bendy 0.6.1 value/Value#Bytes#(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(&[1, 2, 3])), b"3:\x01\x02\x03"); |
| 318 | caserust-analyzer cargo bendy 0.6.1 value/tests/case().(Valuerust-analyzer cargo bendy 0.6.1 value/Value#::Bytesrust-analyzer cargo bendy 0.6.1 value/Value#Bytes#(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![1, 2, 3])), b"3:\x01\x02\x03"); |
| 319 | } |
| 320 | |
| 321 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 322 | fn dictrust-analyzer cargo bendy 0.6.1 value/tests/dict().() { |
| 323 | case_implrust-analyzer cargo bendy 0.6.1 value/tests/case_impl().(Valuerust-analyzer cargo bendy 0.6.1 value/Value#::Dictrust-analyzer cargo bendy 0.6.1 value/Value#Dict#(BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V>`]new().()), 1, "de"); |
| 324 | |
| 325 | let mut dict = BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V>`]new().(); |
| 326 | dict.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]insert().(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#("foo".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()), Valuerust-analyzer cargo bendy 0.6.1 value/Value#::Integerrust-analyzer cargo bendy 0.6.1 value/Value#Integer#(1)); |
| 327 | dict.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]insert().(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#("bar".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()), Valuerust-analyzer cargo bendy 0.6.1 value/Value#::Integerrust-analyzer cargo bendy 0.6.1 value/Value#Integer#(2)); |
| 328 | case_implrust-analyzer cargo bendy 0.6.1 value/tests/case_impl().(Valuerust-analyzer cargo bendy 0.6.1 value/Value#::Dictrust-analyzer cargo bendy 0.6.1 value/Value#Dict#(dict), 1, "d3:bari2e3:fooi1ee"); |
| 329 | } |
| 330 | |
| 331 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 332 | fn integerrust-analyzer cargo bendy 0.6.1 value/tests/integer().() { |
| 333 | caserust-analyzer cargo bendy 0.6.1 value/tests/case().(Valuerust-analyzer cargo bendy 0.6.1 value/Value#::Integerrust-analyzer cargo bendy 0.6.1 value/Value#Integer#(0), "i0e"); |
| 334 | caserust-analyzer cargo bendy 0.6.1 value/tests/case().(Valuerust-analyzer cargo bendy 0.6.1 value/Value#::Integerrust-analyzer cargo bendy 0.6.1 value/Value#Integer#(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().1), "i-1e"); |
| 335 | } |
| 336 | |
| 337 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 338 | fn listrust-analyzer cargo bendy 0.6.1 value/tests/list().() { |
| 339 | case_implrust-analyzer cargo bendy 0.6.1 value/tests/case_impl().(Valuerust-analyzer cargo bendy 0.6.1 value/Value#::Listrust-analyzer cargo bendy 0.6.1 value/Value#List#(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().()), 1, "le"); |
| 340 | case_implrust-analyzer cargo bendy 0.6.1 value/tests/case_impl().( |
| 341 | Valuerust-analyzer cargo bendy 0.6.1 value/Value#::Listrust-analyzer cargo bendy 0.6.1 value/Value#List#(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 342 | Valuerust-analyzer cargo bendy 0.6.1 value/Value#::Integerrust-analyzer cargo bendy 0.6.1 value/Value#Integer#(0), |
| 343 | Valuerust-analyzer cargo bendy 0.6.1 value/Value#::Bytesrust-analyzer cargo bendy 0.6.1 value/Value#Bytes#(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(&[1, 2, 3])), |
| 344 | ]), |
| 345 | 1, |
| 346 | b"li0e3:\x01\x02\x03e", |
| 347 | ); |
| 348 | } |
| 349 | } |