rust-ipfs/examples/client2.rs

23 lines
775 B
Rust
Raw Normal View History

2019-02-21 22:28:59 +01:00
#![feature(async_await, await_macro, futures_api)]
use futures::future::FutureObj;
2019-02-13 23:46:55 +01:00
use futures::prelude::*;
2019-02-18 20:49:57 +01:00
use ipfs::{Block, Ipfs, IpfsOptions, Types};
2019-02-13 23:46:55 +01:00
fn main() {
2019-02-18 18:52:45 +01:00
let options = IpfsOptions::test();
env_logger::Builder::new().parse(&options.ipfs_log).init();
2019-02-18 20:49:57 +01:00
let mut ipfs = Ipfs::<Types>::new(options);
2019-02-13 23:46:55 +01:00
let block = Block::from("hello block\n");
let cid = Block::from("hello block2\n").cid();
2019-02-21 22:28:59 +01:00
tokio::run(FutureObj::new(Box::new(async move {
tokio::spawn(ipfs.start_daemon().compat());
2019-02-22 13:00:28 +01:00
await!(ipfs.put_block(block)).unwrap();
2019-02-22 15:51:37 +01:00
let block = await!(ipfs.get_block(cid)).unwrap();
2019-02-21 22:28:59 +01:00
println!("Received block with contents: {:?}",
2019-02-13 23:46:55 +01:00
String::from_utf8_lossy(&block.data()));
2019-02-21 22:28:59 +01:00
Ok(())
})).compat());
2019-02-13 23:46:55 +01:00
}