From a52193b7ab7fea2428ec69548de5bfd3e2d5f0f2 Mon Sep 17 00:00:00 2001 From: Richard Bradfield Date: Thu, 1 Feb 2024 10:20:15 +0000 Subject: [PATCH] Update examples to latest Tokio/Futures --- Cargo.toml | 1 + examples/simple.rs | 6 +++--- examples/sync.rs | 2 +- src/lib.rs | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9a7d39a..739ec32 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,3 +20,4 @@ edition = "2018" thiserror = "1.0" tokio = { version = "1", features = ["rt", "rt-multi-thread", "net", "io-util", "time", "macros"] } tokio-util = { version = "0.7", features = ["codec"] } +futures = "0.3.30" diff --git a/examples/simple.rs b/examples/simple.rs index 102b499..4464193 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -1,18 +1,18 @@ use rmonitor::codec::RMonitorDecoder; use std::error::Error; use std::time::Duration; +use futures::StreamExt; use tokio::net::TcpStream; -use tokio::stream::StreamExt; use tokio::time::timeout; use tokio_util::codec::FramedRead; #[tokio::main] async fn main() -> Result<(), Box> { - let stream = TcpStream::connect("127.0.0.1:4000").await?; + let stream = TcpStream::connect("127.0.0.1:50000").await?; let mut reader = FramedRead::new(stream, RMonitorDecoder::new_with_max_length(2048)); - while let Ok(Some(Ok(event))) = timeout(Duration::from_millis(10), reader.next()).await { + while let Ok(Some(Ok(event))) = timeout(Duration::from_secs(5), reader.next()).await { println!("{:?}", event); } diff --git a/examples/sync.rs b/examples/sync.rs index 7ef3b07..0f912a9 100644 --- a/examples/sync.rs +++ b/examples/sync.rs @@ -1,4 +1,4 @@ -use bytes::{BufMut, BytesMut}; +use tokio_util::bytes::{BufMut, BytesMut}; use rmonitor::codec::RMonitorDecoder; use std::io::Read; use std::net::TcpStream; diff --git a/src/lib.rs b/src/lib.rs index f83fe92..66b49d5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,7 +10,7 @@ //! use rmonitor::RMonitorDecoder; //! # use std::error::Error; //! use tokio::net::TcpStream; -//! # use tokio::stream::StreamExt; +//! use futures::stream::StreamExt; //! use tokio_util::codec::FramedRead; //! //! #[tokio::main]