summaryrefslogtreecommitdiffstats
path: root/ipfs-api/examples/add_file.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ipfs-api/examples/add_file.rs')
-rw-r--r--ipfs-api/examples/add_file.rs22
1 files changed, 9 insertions, 13 deletions
diff --git a/ipfs-api/examples/add_file.rs b/ipfs-api/examples/add_file.rs
index 2361986..3015684 100644
--- a/ipfs-api/examples/add_file.rs
+++ b/ipfs-api/examples/add_file.rs
@@ -6,26 +6,22 @@
// copied, modified, or distributed except according to those terms.
//
-use futures::Future;
use ipfs_api::IpfsClient;
use std::fs::File;
-use tokio::runtime::current_thread::Runtime;
// Creates an Ipfs client, and adds this source file to Ipfs.
//
-fn main() {
- println!("note: this must be run in the root of the project repository");
- println!("connecting to localhost:5001...");
+#[cfg_attr(feature = "actix", actix_rt::main)]
+#[cfg_attr(feature = "hyper", tokio::main)]
+async fn main() {
+ eprintln!("note: this must be run in the root of the project repository");
+ eprintln!("connecting to localhost:5001...");
let client = IpfsClient::default();
let file = File::open(file!()).expect("could not read source file");
- let req = client
- .add(file)
- .map(|add| println!("added file: {:?}", add))
- .map_err(|e| eprintln!("{}", e));
- Runtime::new()
- .expect("tokio runtime")
- .block_on(req)
- .expect("successful response");
+ match client.add(file).await {
+ Ok(file) => eprintln!("added file: {:?}", file),
+ Err(e) => eprintln!("error adding file: {}", e),
+ }
}