summaryrefslogtreecommitdiffstats
path: root/examples/imagepull.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/imagepull.rs')
-rw-r--r--examples/imagepull.rs23
1 files changed, 13 insertions, 10 deletions
diff --git a/examples/imagepull.rs b/examples/imagepull.rs
index 84a6149..5b3fbf4 100644
--- a/examples/imagepull.rs
+++ b/examples/imagepull.rs
@@ -1,22 +1,25 @@
// cargo run --example imagepull busybox
+use futures::StreamExt;
use shiplift::{Docker, PullOptions};
use std::env;
-use tokio::prelude::{Future, Stream};
-fn main() {
+#[tokio::main]
+async fn main() {
env_logger::init();
let docker = Docker::new();
let img = env::args()
.nth(1)
.expect("You need to specify an image name");
- let fut = docker
+
+ let mut stream = docker
.images()
- .pull(&PullOptions::builder().image(img).build())
- .for_each(|output| {
- println!("{:?}", output);
- Ok(())
- })
- .map_err(|e| eprintln!("Error: {}", e));
- tokio::run(fut);
+ .pull(&PullOptions::builder().image(img).build());
+
+ while let Some(pull_result) = stream.next().await {
+ match pull_result {
+ Ok(output) => println!("{:?}", output),
+ Err(e) => eprintln!("Error: {}", e),
+ }
+ }
}