| 1 | use futuresrust-analyzer cargo futures 0.3.34 crate/::executorrust-analyzer cargo futures 0.3.34 executor/; |
| 2 | use futuresrust-analyzer cargo futures 0.3.34 crate/::streamrust-analyzer cargo futures-util 0.3.34 stream/::StreamExtrust-analyzer cargo futures-util 0.3.34 stream/stream/StreamExt#; |
| 3 | use futuresrust-analyzer cargo futures 0.3.34 crate/::AsyncReadrust-analyzer cargo futures-io 0.3.34 if_std/AsyncRead#; |
| 4 | use futures_codecrust-analyzer cargo futures_codec 0.4.1 crate/::{Decoderrust-analyzer cargo futures_codec 0.4.1 decoder/Decoder#, FramedReadrust-analyzer cargo futures_codec 0.4.1 framed_read/FramedRead#, LinesCodecrust-analyzer cargo futures_codec 0.4.1 codec/lines/LinesCodec#, BytesMutrust-analyzer cargo bytes 1.12.1 bytes_mut/BytesMut#}; |
| 5 | use 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/; |
| 6 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/::Pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/Pin#; |
| 7 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::taskrust-analyzer cargo std https://github.com/rust-lang/rust/library/std task/::{Contextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/Context#, Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#}; |
| 8 | |
| 9 | // Sends two lines at once, then nothing else forever |
| 10 | struct MockBurstySenderrust-analyzer cargo futures_codec 0.4.1 MockBurstySender# { |
| 11 | sentrust-analyzer cargo futures_codec 0.4.1 MockBurstySender#sent.: bool, |
| 12 | } |
| 13 | impl AsyncReadrust-analyzer cargo futures-io 0.3.34 if_std/AsyncRead# for MockBurstySenderrust-analyzer cargo futures_codec 0.4.1 MockBurstySender# { |
| 14 | fn poll_readrust-analyzer cargo futures_codec 0.4.1 impl#[MockBurstySender][AsyncRead]poll_read().( |
| 15 | mut self: Pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/Pin#<&mut Selfrust-analyzer cargo futures_codec 0.4.1 impl#[MockBurstySender][AsyncRead]>, |
| 16 | _cx: &mut Contextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/Context#<'_>, |
| 17 | buf: &mut [u8], |
| 18 | ) -> Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#<iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<usize>> { |
| 19 | const MESSAGESrust-analyzer cargo futures_codec 0.4.1 MESSAGES.: &'static [u8] = b"one\ntwo\n"; |
| 20 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.sentrust-analyzer cargo futures_codec 0.4.1 MockBurstySender#sent. && buf.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().MESSAGESrust-analyzer cargo futures_codec 0.4.1 MESSAGES..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() { |
| 21 | self.sentrust-analyzer cargo futures_codec 0.4.1 MockBurstySender#sent. = true; |
| 22 | buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#MESSAGESrust-analyzer cargo futures_codec 0.4.1 MESSAGES..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut()..clone_from_slicerust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]clone_from_slice().(MESSAGESrust-analyzer cargo futures_codec 0.4.1 MESSAGES.); |
| 23 | Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#::Readyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#Ready#(Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(MESSAGESrust-analyzer cargo futures_codec 0.4.1 MESSAGES..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().())) |
| 24 | } else { |
| 25 | Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#::Pendingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#Pending# |
| 26 | } |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 31 | fn line_read_multirust-analyzer cargo futures_codec 0.4.1 line_read_multi().() { |
| 32 | let io = MockBurstySenderrust-analyzer cargo futures_codec 0.4.1 MockBurstySender# { sentrust-analyzer cargo futures_codec 0.4.1 MockBurstySender#sent.: false }; |
| 33 | let mut framed = FramedReadrust-analyzer cargo futures_codec 0.4.1 framed_read/FramedRead#::newrust-analyzer cargo futures_codec 0.4.1 framed_read/impl#[`FramedRead<T, D>`]new().(io, LinesCodecrust-analyzer cargo futures_codec 0.4.1 codec/lines/LinesCodec# {}); |
| 34 | let one = executorrust-analyzer cargo futures 0.3.34 executor/::block_onrust-analyzer cargo futures-executor 0.3.34 local_pool/block_on().(framed.nextrust-analyzer cargo futures-util 0.3.34 stream/stream/StreamExt#next().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 35 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(one, "one\n"); |
| 36 | let two = executorrust-analyzer cargo futures 0.3.34 executor/::block_onrust-analyzer cargo futures-executor 0.3.34 local_pool/block_on().(framed.nextrust-analyzer cargo futures-util 0.3.34 stream/stream/StreamExt#next().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 37 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(two, "two\n"); |
| 38 | } |
| 39 | |
| 40 | struct OneByteAtATimerust-analyzer cargo futures_codec 0.4.1 OneByteAtATime#<'a> { |
| 41 | inputrust-analyzer cargo futures_codec 0.4.1 OneByteAtATime#input.: &'a [u8], |
| 42 | } |
| 43 | impl AsyncReadrust-analyzer cargo futures-io 0.3.34 if_std/AsyncRead# for OneByteAtATimerust-analyzer cargo futures_codec 0.4.1 OneByteAtATime#<'_> { |
| 44 | fn poll_readrust-analyzer cargo futures_codec 0.4.1 impl#[`OneByteAtATime<'_>`][AsyncRead]poll_read().( |
| 45 | mut self: Pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/Pin#<&mut Selfrust-analyzer cargo futures_codec 0.4.1 impl#[`OneByteAtATime<'_>`][AsyncRead]>, |
| 46 | _cx: &mut Contextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/Context#<'_>, |
| 47 | buf: &mut [u8], |
| 48 | ) -> Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#<iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<usize>> { |
| 49 | if self.inputrust-analyzer cargo futures_codec 0.4.1 OneByteAtATime#input..is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() { |
| 50 | Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#::Readyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#Ready#(Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(0)) |
| 51 | } else { |
| 52 | buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut(). = self.inputrust-analyzer cargo futures_codec 0.4.1 OneByteAtATime#input.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 53 | self.inputrust-analyzer cargo futures_codec 0.4.1 OneByteAtATime#input. = &self.inputrust-analyzer cargo futures_codec 0.4.1 OneByteAtATime#input.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 54 | Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#::Readyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#Ready#(Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(1)) |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | /// A decoder that only returns `a` characters from the input. |
| 60 | struct AllTheAsrust-analyzer cargo futures_codec 0.4.1 AllTheAs#; |
| 61 | |
| 62 | impl Decoderrust-analyzer cargo futures_codec 0.4.1 decoder/Decoder# for AllTheAsrust-analyzer cargo futures_codec 0.4.1 AllTheAs# { |
| 63 | type Itemrust-analyzer cargo futures_codec 0.4.1 impl#[AllTheAs][Decoder]Item# = char; |
| 64 | type Errorrust-analyzer cargo futures_codec 0.4.1 impl#[AllTheAs][Decoder]Error# = 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#; |
| 65 | |
| 66 | fn decoderust-analyzer cargo futures_codec 0.4.1 impl#[AllTheAs][Decoder]decode().(&mut self, src: &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 impl#[AllTheAs][Decoder]::Itemrust-analyzer cargo futures_codec 0.4.1 decoder/Decoder#Item#>, Selfrust-analyzer cargo futures_codec 0.4.1 impl#[AllTheAs][Decoder]::Errorrust-analyzer cargo futures_codec 0.4.1 decoder/Decoder#Error#> { |
| 67 | while !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().src.is_emptyrust-analyzer cargo bytes 1.12.1 bytes_mut/impl#[BytesMut]is_empty().() { |
| 68 | let buf = src.split_torust-analyzer cargo bytes 1.12.1 bytes_mut/impl#[BytesMut]split_to().(1); |
| 69 | let c = char::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/convert/impl#[char][`From<u8>`]from().(buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().); |
| 70 | if c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'a' { |
| 71 | return 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#(c)); |
| 72 | } |
| 73 | } |
| 74 | 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#) |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 79 | fn read_few_messagesrust-analyzer cargo futures_codec 0.4.1 read_few_messages().() { |
| 80 | let string: &[u8] = b"aabbbabbbabbbabb"; |
| 81 | let input = OneByteAtATimerust-analyzer cargo futures_codec 0.4.1 OneByteAtATime# { inputrust-analyzer cargo futures_codec 0.4.1 OneByteAtATime#input.: string }; |
| 82 | let mut framed = FramedReadrust-analyzer cargo futures_codec 0.4.1 framed_read/FramedRead#::newrust-analyzer cargo futures_codec 0.4.1 framed_read/impl#[`FramedRead<T, D>`]new().(input, AllTheAsrust-analyzer cargo futures_codec 0.4.1 AllTheAs#); |
| 83 | for _ in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#5 { |
| 84 | let item = executorrust-analyzer cargo futures 0.3.34 executor/::block_onrust-analyzer cargo futures-executor 0.3.34 local_pool/block_on().(framed.nextrust-analyzer cargo futures-util 0.3.34 stream/stream/StreamExt#next().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 85 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(item, 'a'); |
| 86 | } |
| 87 | } |