diff options
Diffstat (limited to 'ipfs-api/examples/add_file.rs')
-rw-r--r-- | ipfs-api/examples/add_file.rs | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/ipfs-api/examples/add_file.rs b/ipfs-api/examples/add_file.rs index 2361986..798a5f2 100644 --- a/ipfs-api/examples/add_file.rs +++ b/ipfs-api/examples/add_file.rs @@ -6,26 +6,21 @@ // 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..."); +#[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), + } } |