diff options
Diffstat (limited to 'examples/imagepull_auth.rs')
-rw-r--r-- | examples/imagepull_auth.rs | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/examples/imagepull_auth.rs b/examples/imagepull_auth.rs index 1c559c7..6f0ceec 100644 --- a/examples/imagepull_auth.rs +++ b/examples/imagepull_auth.rs @@ -1,10 +1,11 @@ // cargo run --example imagepull_auth busybox username password +use futures::StreamExt; use shiplift::{Docker, PullOptions, RegistryAuth}; 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() @@ -16,13 +17,15 @@ fn main() { .username(username) .password(password) .build(); - let fut = docker + + let mut stream = docker .images() - .pull(&PullOptions::builder().image(img).auth(auth).build()) - .for_each(|output| { - println!("{:?}", output); - Ok(()) - }) - .map_err(|e| eprintln!("Error: {}", e)); - tokio::run(fut); + .pull(&PullOptions::builder().image(img).auth(auth).build()); + + while let Some(pull_result) = stream.next().await { + match pull_result { + Ok(output) => println!("{:?}", output), + Err(e) => eprintln!("{}", e), + } + } } |