chore sync readme with examples/readme.rs
looked into using skeptic but it apparently compiles the README.md code
with by calling `rustc` directly so we end up with nightly ipfs being
linked against readme testcase compiled with stable, which unsurpringly
does not work.
Currently implements an altruistic bitswap strategy over mdns.
## Getting started
-```rust
-#![feature(async_await, await_macro, futures_api)]
+```rust,no-run
use ipfs::{Ipfs, IpfsOptions, Ipld, Types};
use futures::join;
+use futures::{FutureExt, TryFutureExt};
fn main() {
let options = IpfsOptions::<Types>::default();
env_logger::Builder::new().parse_filters(&options.ipfs_log).init();
- let mut ipfs = Ipfs::new(options);
- tokio::run_async(async move {
+ tokio::runtime::current_thread::block_on_all(async move {
// Start daemon and initialize repo
- let fut = ipfs.start_daemon().unwrap();
- tokio::spawn_async(fut);
- await!(ipfs.init_repo()).unwrap();
- await!(ipfs.open_repo()).unwrap();
+ let (ipfs, fut) = Ipfs::new(options).start().await.unwrap();
+ tokio::spawn(fut.unit_error().boxed().compat());
// Create a DAG
let block1: Ipld = "block1".to_string().into();
@@ -28,7 +25,7 @@ fn main() {
let f2 = ipfs.put_dag(block2);
let (res1, res2) = join!(f1, f2);
let root: Ipld = vec![res1.unwrap(), res2.unwrap()].into();
- let path = await!(ipfs.put_dag(root)).unwrap();
+ let path = ipfs.put_dag(root).await.unwrap();
// Query the DAG
let path1 = path.sub_path("0").unwrap();
@@ -41,10 +38,12 @@ fn main() {
// Exit
ipfs.exit_daemon();
- });
+ }.unit_error().boxed().compat()).unwrap();
}
```
+Note: `rust-ipfs` currently requires nightly, see `rust-toolchain` and `.travis.yml` for the tested version.
+
## License
ISC License
