From 9d4d076189822e32574f8123efe21c732103f4d4 Mon Sep 17 00:00:00 2001 From: Lucio Franco Date: Wed, 4 Mar 2020 15:54:41 -0500 Subject: codec: change Encoder to take &Item (#1746) Co-authored-by: Markus Westerlind --- examples/Cargo.toml | 2 +- examples/chat.rs | 6 ++---- examples/tinydb.rs | 2 +- examples/tinyhttp.rs | 3 +-- 4 files changed, 5 insertions(+), 8 deletions(-) (limited to 'examples') diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 423ffe02..a25f526f 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" [dev-dependencies] tokio = { version = "0.2.0", path = "../tokio", features = ["full"] } -tokio-util = { version = "0.2.0", path = "../tokio-util", features = ["full"] } +tokio-util = { version = "0.3.0", path = "../tokio-util", features = ["full"] } bytes = "0.5" futures = "0.3.0" http = "0.2" diff --git a/examples/chat.rs b/examples/chat.rs index fac43cbf..b3fb727a 100644 --- a/examples/chat.rs +++ b/examples/chat.rs @@ -193,9 +193,7 @@ async fn process( let mut lines = Framed::new(stream, LinesCodec::new()); // Send a prompt to the client to enter their username. - lines - .send(String::from("Please enter your username:")) - .await?; + lines.send("Please enter your username:").await?; // Read the first line from the `LineCodec` stream to get the username. let username = match lines.next().await { @@ -232,7 +230,7 @@ async fn process( // A message was received from a peer. Send it to the // current user. Ok(Message::Received(msg)) => { - peer.lines.send(msg).await?; + peer.lines.send(&msg).await?; } Err(e) => { println!( diff --git a/examples/tinydb.rs b/examples/tinydb.rs index 7c71dedf..c1af2541 100644 --- a/examples/tinydb.rs +++ b/examples/tinydb.rs @@ -130,7 +130,7 @@ async fn main() -> Result<(), Box> { let response = response.serialize(); - if let Err(e) = lines.send(response).await { + if let Err(e) = lines.send(response.as_str()).await { println!("error on sending response; error = {:?}", e); } } diff --git a/examples/tinyhttp.rs b/examples/tinyhttp.rs index 9ac2806e..732da0d6 100644 --- a/examples/tinyhttp.rs +++ b/examples/tinyhttp.rs @@ -96,8 +96,7 @@ struct Http; /// Implementation of encoding an HTTP response into a `BytesMut`, basically /// just writing out an HTTP/1.1 response. -impl Encoder for Http { - type Item = Response; +impl Encoder> for Http { type Error = io::Error; fn encode(&mut self, item: Response, dst: &mut BytesMut) -> io::Result<()> { -- cgit v1.2.3