Skip to content

Instantly share code, notes, and snippets.

@yoshuawuyts
Last active May 16, 2017 16:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yoshuawuyts/1b59434bce5c66f8edc159e7d3df3eff to your computer and use it in GitHub Desktop.
Save yoshuawuyts/1b59434bce5c66f8edc159e7d3df3eff to your computer and use it in GitHub Desktop.
Rough rust translation of the https://github.com/ssbc/secure-scuttlebutt example
extern crate ssb_keys;
extern crate ssb;
extern crate mio;
#[macro_use]
extern crate pull;
const pathToSecret: String = "/tmp/ssb1-secret";
const pathToDB: String = "/tmp/ssb1/";
struct Msg {
name: &str,
text: &str,
}
fn main () {
let ev = mio::EventLoop::new();
let keys = ssb_keys::generate();
let ssb = ssb::create(pathToDB);
let feed = ssb.createFeed(ev, keys);
// send a message
let msg = Msg { name: "post", text: "My first post!" };
feed.add(msg, |res: ssb::FeedResponse| {
println!("{}", res.msg);
println!("{}", res.hash);
});
// stream all messages for all keypairs
pull!(ssb::createFeedStream(ev), pull::collect(|res: Option<(), i32>| {
println!("{}", res);
}));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment