From 20255eaad5901e2066fcda5b71aa774036d87469 Mon Sep 17 00:00:00 2001 From: Fenhl Date: Sat, 6 Jan 2024 17:23:53 +0000 Subject: [PATCH] Update chase dependency for futures 0.3 --- Cargo.lock | 13 +++++++------ crate/wurstminebot/Cargo.toml | 3 +-- crate/wurstminebot/src/log.rs | 26 +++++++++++--------------- 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e788f0a..0fd78fe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -439,10 +439,11 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chase" version = "0.1.8" -source = "git+https://github.com/fenhl/chase-rs?branch=dev-fenhl#5f0811e9948c7f7e3feb50b853541beaf19c93e2" +source = "git+https://github.com/fenhl/chase-rs?branch=wmb#1b9ca4f8baef523d9371bf8aadc7ac1667563282" dependencies = [ - "futures 0.1.31", "thiserror", + "tokio", + "wheel", "windows 0.52.0", ] @@ -4032,7 +4033,7 @@ checksum = "1778a42e8b3b90bff8d0f5032bf22250792889a5cdc752aa0020c84abe3aaf10" [[package]] name = "wheel" version = "0.13.1" -source = "git+https://github.com/fenhl/wheel?branch=main#9330871c35d027d78ef975516ffa1b5a640400a7" +source = "git+https://github.com/fenhl/wheel?branch=main#9603e4b87e4335270d32ab1f31021f33df63c95e" dependencies = [ "async-trait", "clap", @@ -4050,7 +4051,7 @@ dependencies = [ [[package]] name = "wheel-derive" version = "0.13.1" -source = "git+https://github.com/fenhl/wheel?branch=main#9330871c35d027d78ef975516ffa1b5a640400a7" +source = "git+https://github.com/fenhl/wheel?branch=main#9603e4b87e4335270d32ab1f31021f33df63c95e" dependencies = [ "itertools 0.12.0", "proc-macro2", @@ -4263,9 +4264,9 @@ checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" [[package]] name = "winnow" -version = "0.5.32" +version = "0.5.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8434aeec7b290e8da5c3f0d628cb0eac6cabcb31d14bb74f779a08109a5914d6" +checksum = "b7520bbdec7211caa7c4e682eb1fbe07abe20cee6756b6e00f537c82c11816aa" dependencies = [ "memchr", ] diff --git a/crate/wurstminebot/Cargo.toml b/crate/wurstminebot/Cargo.toml index 60de84e..75c15ce 100644 --- a/crate/wurstminebot/Cargo.toml +++ b/crate/wurstminebot/Cargo.toml @@ -32,8 +32,7 @@ features = ["full"] [dependencies.chase] git = "https://github.com/fenhl/chase-rs" -branch = "dev-fenhl" -features = ["stream"] +branch = "wmb" [dependencies.derive_more] version = "0.99" diff --git a/crate/wurstminebot/src/log.rs b/crate/wurstminebot/src/log.rs index fe1f992..250bd54 100644 --- a/crate/wurstminebot/src/log.rs +++ b/crate/wurstminebot/src/log.rs @@ -7,12 +7,8 @@ use { sync::Arc, time::Duration, }, - chase::{ - ChaseError, - Chaser, - }, + chase::Chaser, futures::{ - compat::Stream01CompatExt as _, future::try_join_all, pin_mut, prelude::*, @@ -43,7 +39,10 @@ use { }, sync::RwLock, }, - tokio_stream::wrappers::LinesStream, + tokio_stream::wrappers::{ + LinesStream, + ReceiverStream, + }, tokio_util::io::StreamReader, url::Url, wheel::{ @@ -58,7 +57,7 @@ use { #[derive(Debug, thiserror::Error)] pub enum Error { - #[error(transparent)] Chase(#[from] ChaseError), + #[error(transparent)] Chase(#[from] chase::Error), #[error(transparent)] Io(#[from] io::Error), #[error(transparent)] Json(#[from] serde_json::Error), #[error(transparent)] Minecraft(#[from] systemd_minecraft::Error), @@ -282,12 +281,9 @@ impl Line { fn follow(http_client: reqwest::Client, world: &World) -> impl Stream> { let log_path = world.dir().join("logs/latest.log"); stream::once(async { - let init_lines = LinesStream::new(BufReader::new(File::open(&log_path).await?).lines()).try_fold(0, |acc, _| async move { Ok(acc + 1) }).await?; - let mut chaser = Chaser::new(log_path); - chaser.line = chase::Line(init_lines); - let (rx, _ /*handle*/) = chaser.run_stream()?; //TODO handle errors in the stream using `handle` - let stream = rx.compat() - .map_err(|()| Error::Channel) + let init_lines = LinesStream::new(BufReader::new(File::open(&log_path).await?).lines()).try_fold(0, |acc, _| future::ok(acc + 1)).await?; + let chaser = Chaser::new(log_path, chase::Line(init_lines)); + let stream = ReceiverStream::new(chaser.run()) .scan( Arc::new(RwLock::new(FollowerState { minecraft_version: None, //TODO check log history for current Minecraft version @@ -298,8 +294,8 @@ fn follow(http_client: reqwest::Client, world: &World) -> impl Stream Line::parse(state, &line).await, - Err(e) => Err(e), + Ok(line) => Line::parse(state, &line).await, + Err(e) => Err(e.into()), }) } },