| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::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#; |
| 2 | |
| 3 | use craterust-analyzer cargo futures_codec 0.4.1 crate/::{Decoderrust-analyzer cargo futures_codec 0.4.1 decoder/Decoder#, Encoderrust-analyzer cargo futures_codec 0.4.1 encoder/Encoder#}; |
| 4 | use bytesrust-analyzer cargo bytes 1.12.1 crate/::{Bufrust-analyzer cargo bytes 1.12.1 buf/buf_impl/Buf#, BufMutrust-analyzer cargo bytes 1.12.1 buf/buf_mut/BufMut#, BytesMutrust-analyzer cargo bytes 1.12.1 bytes_mut/BytesMut#}; |
| 5 | |
| 6 | use serderust-analyzer cargo serde 1.0.229 crate/::{Deserializerust-analyzer cargo serde_core 1.0.229 de/Deserialize#, Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize#}; |
| 7 | use serde_jsonrust-analyzer cargo serde_json 1.0.151 crate/; |
| 8 | |
| 9 | /// A codec for JSON encoding and decoding using serde_json |
| 10 | /// Enc is the type to encode, Dec is the type to decode |
| 11 | /// ``` |
| 12 | /// # use futures::{executor, SinkExt, TryStreamExt}; |
| 13 | /// # use futures::io::Cursor; |
| 14 | /// use serde::{Serialize, Deserialize}; |
| 15 | /// use futures_codec::{JsonCodec, Framed}; |
| 16 | /// |
| 17 | /// #[derive(Serialize, Deserialize)] |
| 18 | /// struct Something { |
| 19 | /// pub data: u16, |
| 20 | /// } |
| 21 | /// |
| 22 | /// async move { |
| 23 | /// # let mut buf = vec![]; |
| 24 | /// # let stream = Cursor::new(&mut buf); |
| 25 | /// // let stream = ... |
| 26 | /// let codec = JsonCodec::<Something, Something>::new(); |
| 27 | /// let mut framed = Framed::new(stream, codec); |
| 28 | /// |
| 29 | /// while let Some(s) = framed.try_next().await.unwrap() { |
| 30 | /// println!("{:?}", s.data); |
| 31 | /// } |
| 32 | /// }; |
| 33 | /// ``` |
| 34 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 35 | pub struct JsonCodecrust-analyzer cargo futures_codec 0.4.1 codec/json/JsonCodec#<Enc, Dec> { |
| 36 | encrust-analyzer cargo futures_codec 0.4.1 codec/json/JsonCodec#enc.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#<Enc>, |
| 37 | decrust-analyzer cargo futures_codec 0.4.1 codec/json/JsonCodec#dec.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#<Dec>, |
| 38 | } |
| 39 | |
| 40 | /// JSON Codec error enumeration |
| 41 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 42 | pub enum JsonCodecErrorrust-analyzer cargo futures_codec 0.4.1 codec/json/JsonCodecError# { |
| 43 | /// IO error |
| 44 | Iorust-analyzer cargo futures_codec 0.4.1 codec/json/JsonCodecError#Io#(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#), |
| 45 | /// JSON error |
| 46 | Jsonrust-analyzer cargo futures_codec 0.4.1 codec/json/JsonCodecError#Json#(serde_jsonrust-analyzer cargo serde_json 1.0.151 crate/::Errorrust-analyzer cargo serde_json 1.0.151 error/Error#), |
| 47 | } |
| 48 | |
| 49 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#> for JsonCodecErrorrust-analyzer cargo futures_codec 0.4.1 codec/json/JsonCodecError# { |
| 50 | fn fromrust-analyzer cargo futures_codec 0.4.1 codec/json/impl#[JsonCodecError][`From<std::io::Error>`]from().(e: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#) -> JsonCodecErrorrust-analyzer cargo futures_codec 0.4.1 codec/json/JsonCodecError# { |
| 51 | return JsonCodecErrorrust-analyzer cargo futures_codec 0.4.1 codec/json/JsonCodecError#::Iorust-analyzer cargo futures_codec 0.4.1 codec/json/JsonCodecError#Io#(e); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<serde_jsonrust-analyzer cargo serde_json 1.0.151 crate/::Errorrust-analyzer cargo serde_json 1.0.151 error/Error#> for JsonCodecErrorrust-analyzer cargo futures_codec 0.4.1 codec/json/JsonCodecError# { |
| 56 | fn fromrust-analyzer cargo futures_codec 0.4.1 codec/json/impl#[JsonCodecError][`From<serde_json::Error>`]from().(e: serde_jsonrust-analyzer cargo serde_json 1.0.151 crate/::Errorrust-analyzer cargo serde_json 1.0.151 error/Error#) -> JsonCodecErrorrust-analyzer cargo futures_codec 0.4.1 codec/json/JsonCodecError# { |
| 57 | return JsonCodecErrorrust-analyzer cargo futures_codec 0.4.1 codec/json/JsonCodecError#::Jsonrust-analyzer cargo futures_codec 0.4.1 codec/json/JsonCodecError#Json#(e); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | impl<Enc, Dec> JsonCodecrust-analyzer cargo futures_codec 0.4.1 codec/json/JsonCodec#<Enc, Dec> |
| 62 | where |
| 63 | for<'de> Dec: Deserializerust-analyzer cargo serde_core 1.0.229 de/Deserialize#<'de> + 'static, |
| 64 | for<'de> Enc: Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize# + 'static, |
| 65 | { |
| 66 | /// Creates a new `JsonCodec` with the associated types |
| 67 | pub fn newrust-analyzer cargo futures_codec 0.4.1 codec/json/impl#[`JsonCodec<Enc, Dec>`]new().() -> JsonCodecrust-analyzer cargo futures_codec 0.4.1 codec/json/JsonCodec#<Enc, Dec> { |
| 68 | JsonCodecrust-analyzer cargo futures_codec 0.4.1 codec/json/JsonCodec# { |
| 69 | encrust-analyzer cargo futures_codec 0.4.1 codec/json/JsonCodec#enc.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#, |
| 70 | decrust-analyzer cargo futures_codec 0.4.1 codec/json/JsonCodec#dec.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#, |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | impl<Enc, Dec> Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# for JsonCodecrust-analyzer cargo futures_codec 0.4.1 codec/json/JsonCodec#<Enc, Dec> |
| 76 | where |
| 77 | for<'de> Dec: Deserializerust-analyzer cargo serde_core 1.0.229 de/Deserialize#<'de> + 'static, |
| 78 | for<'de> Enc: Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize# + 'static, |
| 79 | { |
| 80 | /// Clone creates a new instance of the `JsonCodec` |
| 81 | fn clonerust-analyzer cargo futures_codec 0.4.1 codec/json/impl#[`JsonCodec<Enc, Dec>`][Clone]clone().(&self) -> JsonCodecrust-analyzer cargo futures_codec 0.4.1 codec/json/JsonCodec#<Enc, Dec> { |
| 82 | JsonCodecrust-analyzer cargo futures_codec 0.4.1 codec/json/JsonCodec#::newrust-analyzer cargo futures_codec 0.4.1 codec/json/impl#[`JsonCodec<Enc, Dec>`]new().() |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | /// Decoder impl parses json objects from bytes |
| 87 | impl<Enc, Dec> Decoderrust-analyzer cargo futures_codec 0.4.1 decoder/Decoder# for JsonCodecrust-analyzer cargo futures_codec 0.4.1 codec/json/JsonCodec#<Enc, Dec> |
| 88 | where |
| 89 | for<'de> Dec: Deserializerust-analyzer cargo serde_core 1.0.229 de/Deserialize#<'de> + 'static, |
| 90 | for<'de> Enc: Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize# + 'static, |
| 91 | { |
| 92 | type Itemrust-analyzer cargo futures_codec 0.4.1 codec/json/impl#[`JsonCodec<Enc, Dec>`][Decoder]Item# = Dec; |
| 93 | type Errorrust-analyzer cargo futures_codec 0.4.1 codec/json/impl#[`JsonCodec<Enc, Dec>`][Decoder]Error# = JsonCodecErrorrust-analyzer cargo futures_codec 0.4.1 codec/json/JsonCodecError#; |
| 94 | |
| 95 | fn decoderust-analyzer cargo futures_codec 0.4.1 codec/json/impl#[`JsonCodec<Enc, Dec>`][Decoder]decode().(&mut self, buf: &mut BytesMutrust-analyzer cargo bytes 1.12.1 bytes_mut/BytesMut#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo futures_codec 0.4.1 codec/json/impl#[`JsonCodec<Enc, Dec>`][Decoder]::Itemrust-analyzer cargo futures_codec 0.4.1 decoder/Decoder#Item#>, Selfrust-analyzer cargo futures_codec 0.4.1 codec/json/impl#[`JsonCodec<Enc, Dec>`][Decoder]::Errorrust-analyzer cargo futures_codec 0.4.1 decoder/Decoder#Error#> { |
| 96 | // Build streaming JSON iterator over data |
| 97 | let de = serde_jsonrust-analyzer cargo serde_json 1.0.151 crate/::Deserializerrust-analyzer cargo serde_json 1.0.151 de/Deserializer#::from_slicerust-analyzer cargo serde_json 1.0.151 de/impl#[`Deserializer<SliceRead<'a>>`]from_slice().(&buf); |
| 98 | let mut iter = de.into_iterrust-analyzer cargo serde_json 1.0.151 de/impl#[`Deserializer<R>`]into_iter().::<Dec>(); |
| 99 | |
| 100 | // Attempt to fetch an item and generate response |
| 101 | let res = match iter.nextrust-analyzer cargo serde_json 1.0.151 de/impl#[`StreamDeserializer<'de, R, T>`][Iterator]next().() { |
| 102 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(v)) => 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#(v)), |
| 103 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ref e)) if e.is_eofrust-analyzer cargo serde_json 1.0.151 error/impl#[Error]is_eof().() => 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#), |
| 104 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e)) => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()), |
| 105 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => 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#), |
| 106 | }; |
| 107 | |
| 108 | // Update offset from iterator |
| 109 | let offset = iter.byte_offsetrust-analyzer cargo serde_json 1.0.151 de/impl#[`StreamDeserializer<'de, R, T>`]byte_offset().(); |
| 110 | |
| 111 | // Advance buffer |
| 112 | buf.advancerust-analyzer cargo bytes 1.12.1 bytes_mut/impl#[BytesMut][Buf]advance().(offset); |
| 113 | |
| 114 | res |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | /// Encoder impl encodes object streams to bytes |
| 119 | impl<Enc, Dec> Encoderrust-analyzer cargo futures_codec 0.4.1 encoder/Encoder# for JsonCodecrust-analyzer cargo futures_codec 0.4.1 codec/json/JsonCodec#<Enc, Dec> |
| 120 | where |
| 121 | for<'de> Dec: Deserializerust-analyzer cargo serde_core 1.0.229 de/Deserialize#<'de> + 'static, |
| 122 | for<'de> Enc: Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize# + 'static, |
| 123 | { |
| 124 | type Itemrust-analyzer cargo futures_codec 0.4.1 codec/json/impl#[`JsonCodec<Enc, Dec>`][Encoder]Item# = Enc; |
| 125 | type Errorrust-analyzer cargo futures_codec 0.4.1 codec/json/impl#[`JsonCodec<Enc, Dec>`][Encoder]Error# = JsonCodecErrorrust-analyzer cargo futures_codec 0.4.1 codec/json/JsonCodecError#; |
| 126 | |
| 127 | fn encoderust-analyzer cargo futures_codec 0.4.1 codec/json/impl#[`JsonCodec<Enc, Dec>`][Encoder]encode().(&mut self, data: Selfrust-analyzer cargo futures_codec 0.4.1 codec/json/impl#[`JsonCodec<Enc, Dec>`][Encoder]::Itemrust-analyzer cargo futures_codec 0.4.1 encoder/Encoder#Item#, buf: &mut BytesMutrust-analyzer cargo bytes 1.12.1 bytes_mut/BytesMut#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Selfrust-analyzer cargo futures_codec 0.4.1 codec/json/impl#[`JsonCodec<Enc, Dec>`][Encoder]::Errorrust-analyzer cargo futures_codec 0.4.1 encoder/Encoder#Error#> { |
| 128 | // Encode json |
| 129 | let j = serde_jsonrust-analyzer cargo serde_json 1.0.151 crate/::to_stringrust-analyzer cargo serde_json 1.0.151 ser/to_string().(&data)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 130 | |
| 131 | // Write to buffer |
| 132 | buf.reserverust-analyzer cargo bytes 1.12.1 bytes_mut/impl#[BytesMut]reserve().(j.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]len().()); |
| 133 | buf.put_slicerust-analyzer cargo bytes 1.12.1 bytes_mut/impl#[BytesMut][BufMut]put_slice().(&j.as_bytesrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_bytes().()); |
| 134 | |
| 135 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | #[cfg(test)] |
| 140 | mod testrust-analyzer cargo futures_codec 0.4.1 codec/json/test/ { |
| 141 | use bytesrust-analyzer cargo bytes 1.12.1 crate/::BytesMutrust-analyzer cargo bytes 1.12.1 bytes_mut/BytesMut#; |
| 142 | use serderust-analyzer cargo serde 1.0.229 crate/::{Deserializerust-analyzer cargo serde_core 1.0.229 de/Deserialize#, Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize#}; |
| 143 | |
| 144 | use superrust-analyzer cargo futures_codec 0.4.1 codec/json/::JsonCodecrust-analyzer cargo futures_codec 0.4.1 codec/json/JsonCodec#; |
| 145 | use craterust-analyzer cargo futures_codec 0.4.1 crate/::{Decoderrust-analyzer cargo futures_codec 0.4.1 decoder/Decoder#, Encoderrust-analyzer cargo futures_codec 0.4.1 encoder/Encoder#}; |
| 146 | |
| 147 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(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:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Serializerust-analyzer cargo serde_derive 1.0.229 Serialize:, Deserializerust-analyzer cargo serde_derive 1.0.229 Deserialize:)] |
| 148 | struct TestStructrust-analyzer cargo futures_codec 0.4.1 codec/json/test/TestStruct# { |
| 149 | pub namerust-analyzer cargo futures_codec 0.4.1 codec/json/test/TestStruct#name.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 150 | pub datarust-analyzer cargo futures_codec 0.4.1 codec/json/test/TestStruct#data.: u16, |
| 151 | } |
| 152 | |
| 153 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 154 | fn json_codec_encode_decoderust-analyzer cargo futures_codec 0.4.1 codec/json/test/json_codec_encode_decode().() { |
| 155 | let mut codec = JsonCodecrust-analyzer cargo futures_codec 0.4.1 codec/json/JsonCodec#::<TestStructrust-analyzer cargo futures_codec 0.4.1 codec/json/test/TestStruct#, TestStructrust-analyzer cargo futures_codec 0.4.1 codec/json/test/TestStruct#>::newrust-analyzer cargo futures_codec 0.4.1 codec/json/impl#[`JsonCodec<Enc, Dec>`]new().(); |
| 156 | let mut buff = BytesMutrust-analyzer cargo bytes 1.12.1 bytes_mut/BytesMut#::newrust-analyzer cargo bytes 1.12.1 bytes_mut/impl#[BytesMut]new().(); |
| 157 | |
| 158 | let item1 = TestStructrust-analyzer cargo futures_codec 0.4.1 codec/json/test/TestStruct# { |
| 159 | namerust-analyzer cargo futures_codec 0.4.1 codec/json/test/TestStruct#name.: "Test name".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), |
| 160 | datarust-analyzer cargo futures_codec 0.4.1 codec/json/test/TestStruct#data.: 16, |
| 161 | }; |
| 162 | codec.encoderust-analyzer cargo futures_codec 0.4.1 codec/json/impl#[`JsonCodec<Enc, Dec>`][Encoder]encode().(item1.clonerust-analyzer cargo futures_codec 0.4.1 codec/json/test/impl#[TestStruct][Clone]clone().(), &mut buff).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 163 | |
| 164 | let item2 = codec.decoderust-analyzer cargo futures_codec 0.4.1 codec/json/impl#[`JsonCodec<Enc, Dec>`][Decoder]decode().(&mut buff).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 165 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(item1, item2); |
| 166 | |
| 167 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(codec.decoderust-analyzer cargo futures_codec 0.4.1 codec/json/impl#[`JsonCodec<Enc, Dec>`][Decoder]decode().(&mut buff).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 168 | |
| 169 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(buff.lenrust-analyzer cargo bytes 1.12.1 bytes_mut/impl#[BytesMut]len().(), 0); |
| 170 | } |
| 171 | |
| 172 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 173 | fn json_codec_partial_decoderust-analyzer cargo futures_codec 0.4.1 codec/json/test/json_codec_partial_decode().() { |
| 174 | let mut codec = JsonCodecrust-analyzer cargo futures_codec 0.4.1 codec/json/JsonCodec#::<TestStructrust-analyzer cargo futures_codec 0.4.1 codec/json/test/TestStruct#, TestStructrust-analyzer cargo futures_codec 0.4.1 codec/json/test/TestStruct#>::newrust-analyzer cargo futures_codec 0.4.1 codec/json/impl#[`JsonCodec<Enc, Dec>`]new().(); |
| 175 | let mut buff = BytesMutrust-analyzer cargo bytes 1.12.1 bytes_mut/BytesMut#::newrust-analyzer cargo bytes 1.12.1 bytes_mut/impl#[BytesMut]new().(); |
| 176 | |
| 177 | let item1 = TestStructrust-analyzer cargo futures_codec 0.4.1 codec/json/test/TestStruct# { |
| 178 | namerust-analyzer cargo futures_codec 0.4.1 codec/json/test/TestStruct#name.: "Test name".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), |
| 179 | datarust-analyzer cargo futures_codec 0.4.1 codec/json/test/TestStruct#data.: 34, |
| 180 | }; |
| 181 | codec.encoderust-analyzer cargo futures_codec 0.4.1 codec/json/impl#[`JsonCodec<Enc, Dec>`][Encoder]encode().(item1.clonerust-analyzer cargo futures_codec 0.4.1 codec/json/test/impl#[TestStruct][Clone]clone().(), &mut buff).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 182 | |
| 183 | let mut start = buff.clonerust-analyzer cargo bytes 1.12.1 bytes_mut/impl#[BytesMut][Clone]clone().().split_torust-analyzer cargo bytes 1.12.1 bytes_mut/impl#[BytesMut]split_to().(4); |
| 184 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(codec.decoderust-analyzer cargo futures_codec 0.4.1 codec/json/impl#[`JsonCodec<Enc, Dec>`][Decoder]decode().(&mut start).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 185 | |
| 186 | codec.decoderust-analyzer cargo futures_codec 0.4.1 codec/json/impl#[`JsonCodec<Enc, Dec>`][Decoder]decode().(&mut buff).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 187 | |
| 188 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(buff.lenrust-analyzer cargo bytes 1.12.1 bytes_mut/impl#[BytesMut]len().(), 0); |
| 189 | } |
| 190 | } |