online log tail implementation
Hi!
I am teaching my self the language by doing little projects. I'm a newbie in rust. Usally I hit the wall quite early.
Now I'm trying to write a tail implementation for "online log files".
Therefore I use the libraries Hyper and Tokio. No suprise :).
The following snippet probably can be written more compact. But it helps me to understand what is going on.
...
let http_body: &mut Body = res.body_mut();
loop {
if http_body.is_end_stream() {
println!("Ende Http");
tokio::time::delay_for(Duration::from_secs(3)).await;
continue;
}
let data = http_body.data().await;
match data {
Some(b) => match b {
Ok(v) => tokio::io::stdout().write_all(&v).await?,
Err(e) => return Err(Box::new(e)),
},
None => tokio::time::delay_for(Duration::from_secs(3)).await,
}
}
...
This prints the content of webpage and fails (panics):
thread 'main' panicked at 'Receiver::next_message called after None
',
note: run with RUST_BACKTRACE=1
environment variable to display a backtrace
The error makes sense, but I'm lacking of ideas how to implement this in a correct matter.
My goal: I want that this program to stay connected and that it continues polling data. If there is new data o print it or else wait and try it later. But just the new data.
Maybe you can point me into the right direction or you know of libraries where I can see the implementation.
The only idea what I can come up with is to implement the HttpBody Trait by copying the Body implementation provided by hyper and modifying it. Which is to hard for me at the moment. But at least I had an starting point.
Here is the code:
Thanks!
Paul