Skip to content

Commit

Permalink
example to ensure structs are send
Browse files Browse the repository at this point in the history
  • Loading branch information
bltavares committed Feb 3, 2020
1 parent f77fe7b commit 2dc8008
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ quickcheck = "0.8.5"
data-encoding = "2.1.2"
remove_dir_all = "0.5.2"
tempfile = "3.1.0"
async-std = "1.5.0"
30 changes: 30 additions & 0 deletions examples/async.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use async_std::task;
use failure::Error;
use hypercore::Feed;
use random_access_storage::RandomAccess;
use std::fmt::Debug;

async fn append<T>(feed: &mut Feed<T>, content: &[u8])
where
T: RandomAccess<Error = Error> + Debug,
{
feed.append(content).unwrap();
}

async fn print<T>(feed: &mut Feed<T>)
where
T: RandomAccess<Error = Error> + Debug,
{
println!("{:?}", feed.get(0));
println!("{:?}", feed.get(1));
}

fn main() {
task::block_on(task::spawn(async {
let mut feed = Feed::default();

append(&mut feed, b"hello").await;
append(&mut feed, b"world").await;
print(&mut feed).await;
}));
}

0 comments on commit 2dc8008

Please sign in to comment.