summaryrefslogtreecommitdiffstats
path: root/examples/export.rs
diff options
context:
space:
mode:
authorEli W. Hunter <42009212+elihunter173@users.noreply.github.com>2020-07-23 23:54:12 -0400
committerGitHub <noreply@github.com>2020-07-23 23:54:12 -0400
commit6cd1d7f93bd6f150341582a1b54087cefffdbf87 (patch)
tree88c109ec79e679d5aa041b20f074cf7b57d97cda /examples/export.rs
parenta4cd2185976ad56b880d5a10374c4dee6d116e6a (diff)
Async/Await Support (continuation of #191) (#229)
* it builds! * remove unused dependencies * bump dependencies * reimplement 'exec' endpoint * update a few more examples * update remaining examples * fix doc tests, remove unused 'read' module * remove feature-gated async closures * split futures dependency to just 'futures-util' * update version and readme * make functions accepting Body generic over Into<Body> again * update changelog * reinstate 'unix-socket' feature * reinstate 'attach' endpoint * fix clippy lints * fix documentation typo * fix container copyfrom/into implementations * add convenience methods for TtyChunk struct * remove 'main' from code example to silence clippy lint * Update hyper to 0.13.1 * Add Send bounds to TtyWriter * Appease clippy * Fix examples * Update issue in changelog Co-authored-by: Daniel Eades <danieleades@hotmail.com> Co-authored-by: Marc Schreiber <marc.schreiber@aixigo.de>
Diffstat (limited to 'examples/export.rs')
-rw-r--r--examples/export.rs26
1 files changed, 12 insertions, 14 deletions
diff --git a/examples/export.rs b/examples/export.rs
index 55d1b7b..34f460d 100644
--- a/examples/export.rs
+++ b/examples/export.rs
@@ -1,8 +1,10 @@
-use shiplift::{errors::Error, Docker};
+use futures::StreamExt;
use std::{env, fs::OpenOptions, io::Write};
-use tokio::prelude::{Future, Stream};
-fn main() {
+use shiplift::{errors::Error, Docker};
+
+#[tokio::main]
+async fn main() {
let docker = Docker::new();
let id = env::args().nth(1).expect("You need to specify an image id");
@@ -11,17 +13,13 @@ fn main() {
.create(true)
.open(format!("{}.tar", &id))
.unwrap();
+
let images = docker.images();
- let fut = images
- .get(&id)
- .export()
- .for_each(move |bytes| {
- export_file
- .write(&bytes[..])
- .map(|n| println!("copied {} bytes", n))
- .map_err(Error::IO)
- })
- .map_err(|e| eprintln!("Error: {}", e));
- tokio::run(fut)
+ while let Some(export_result) = images.get(&id).export().next().await {
+ match export_result.and_then(|bytes| export_file.write(&bytes).map_err(Error::from)) {
+ Ok(n) => println!("copied {} bytes", n),
+ Err(e) => eprintln!("Error: {}", e),
+ }
+ }
}