summaryrefslogtreecommitdiffstats
path: root/examples/stats.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/stats.rs')
-rw-r--r--examples/stats.rs21
1 files changed, 10 insertions, 11 deletions
diff --git a/examples/stats.rs b/examples/stats.rs
index 9e14cf4..063f502 100644
--- a/examples/stats.rs
+++ b/examples/stats.rs
@@ -1,21 +1,20 @@
// cargo run --example stats -- <container>
+use futures::StreamExt;
use shiplift::Docker;
use std::env;
-use tokio::prelude::{Future, Stream};
-fn main() {
+#[tokio::main]
+async fn main() {
let docker = Docker::new();
let containers = docker.containers();
let id = env::args()
.nth(1)
.expect("Usage: cargo run --example stats -- <container>");
- let fut = containers
- .get(&id)
- .stats()
- .for_each(|stat| {
- println!("{:?}", stat);
- Ok(())
- })
- .map_err(|e| eprintln!("Error: {}", e));
- tokio::run(fut);
+
+ while let Some(result) = containers.get(&id).stats().next().await {
+ match result {
+ Ok(stat) => println!("{:?}", stat),
+ Err(e) => eprintln!("Error: {}", e),
+ }
+ }
}