While trying to deserialize into a JSON Value
from a tokio TcpStream
, I'm trying to use this function:
use futures::prelude::*;
use serde_json::Value;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::net::{TcpListener, TcpStream};
use tokio::stream::StreamExt;
use tokio_serde_json::ReadJson;
use tokio_util::codec::{FramedRead, LengthDelimitedCodec};
pub async fn handle_stream(mut stream: TcpStream) {
let length_delimited = FramedRead::new(stream, LengthDelimitedCodec::new());
let mut deserialized = ReadJson::<_, Value>::new(length_delimited);
}
My dependency versions are:
tokio = { version = "0.2.22", features=["full"] }
tokio-util = { version = "0.3.0", features=["full"] }
tokio-serde = "0.6"
serde = "1.0.92"
serde_derive = "1.0.92"
serde_json = "1.0.39"
futures-preview = "0.3.0-alpha"
I got the code from the examples from carllerche/tokio-serde-json
However I get the following error:
error[E0277]: the trait bound `tokio_util::codec::framed_read::FramedRead<tokio::net::tcp::stream::TcpStream, tokio_util::codec::length_delimited::LengthDelimitedCodec>: futures::stream::Stream` is not satisfied
--> src/kad2.rs:141:58
|
141 | let mut deserialized = ReadJson::<_, Value>::new(length_delimited);
| ^^^^^^^^^^^^^^^^ the trait `futures::stream::Stream` is not implemented for `tokio_util::codec::framed_read::FramedRead<tokio::net::tcp::stream::TcpStream, tokio_util::codec::length_delimited::LengthDelimitedCodec>`
|
= note: required by `tokio_serde_json::ReadJson::<T, U>::new`
Is this a case of APIs and recommended libraries having evolved and moved to another way to do things ?
How would I deserialize JSON into a Value
with Tokio now ?