Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: update instructions for running rust examples #1511

Merged
merged 2 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion iroh/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ iroh = { version = "...", default-features = false }

## Running Examples

examples are located in `iroh/examples`. Some have their own cargo.toml to show different use cases, and as such are shipped as their own packages. For these run them with `cargo run --package`. eg: `cargo run --package hello-world`
Examples are located in `iroh/examples`. Run them with `cargo run --example`. eg: `cargo run --example hello-world`. At the top of each example file is a comment describing how to run the example.

# License

Expand Down
7 changes: 7 additions & 0 deletions iroh/examples/client.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//! This example shows the shortest path to working with documents in iroh. This example creates a
//! document and sets an entry with key: "hello", value: "world". The document is completely local.
//!
//! The iroh node that creates the document is backed by an in-memory database and a random peer ID
//!
//! run this example from the project root:
//! $ cargo run --example client
use indicatif::HumanBytes;
use iroh::node::Node;
use iroh_bytes::util::runtime;
Expand Down
5 changes: 5 additions & 0 deletions iroh/examples/dump-blob-fsm.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
//! An example how to download a single blob from a node and write it to stdout.
//!
//! This is using the get finite state machine directly.
//! Run this example on any `iroh get` ticket. You can create a "hello world" ticket with:
//! $ cargo run --example hello-world
//! hello-world will give you a "ticket" argument & example to use with `cargo run -- get --ticket`
//! copy that ticket value (the long string after `--ticket`) & feed it to this example:
//! $ cargo run --example dump-blob-fsm <ticket>
use std::env::args;
use std::str::FromStr;

Expand Down
5 changes: 5 additions & 0 deletions iroh/examples/dump-blob-stream.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
//! An example how to download a single blob from a node and write it to stdout.
//!
//! This is using a helper method to stream the blob.
//! Run this example on any `iroh get` ticket. You can create a "hello world" ticket with:
//! $ cargo run --example hello-world
//! hello-world will give you a "ticket" argument & example to use with `cargo run -- get --ticket`
//! copy that ticket & feed it to this example:
//! $ cargo run --example dump-blob-stream <ticket>
use std::env::args;
use std::io;
use std::str::FromStr;
Expand Down
4 changes: 2 additions & 2 deletions iroh/examples/hello-world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
//! This can be downloaded using the iroh CLI.
//!
//! This is using an in memory database and a random peer id.
//! //! run this example from the project root:
//! $ cargo run -p hello-world
//! run this example from the project root:
//! $ cargo run --example hello-world
use iroh::bytes::util::runtime;
use tracing_subscriber::{prelude::*, EnvFilter};

Expand Down
7 changes: 7 additions & 0 deletions iroh/examples/rpc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
//! An example that runs an iroh node that can be controlled via RPC.
//!
//! Run this example with
//! $ cargo run --example rpc
//! Then in another terminal, run any of the normal iroh CLI commands, which you can run from
//! cargo as well:
//! $ cargo run node stats
//! The `node stats` command will reach out over RPC to the node constructed in the example
use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4};

use clap::Parser;
Expand Down
4 changes: 4 additions & 0 deletions iroh/examples/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
//! By default a new peer id is created when starting the example. To reuse your identity,
//! set the `--secret-key` CLI flag with the secret key printed on a previous invocation.
//!
//! Run with:
//! $ cargo run --example sync --features=example-sync
//! Then follow the instructions printed
//!
//! You can use this with a local DERP server. To do so, run
//! `cargo run --bin derper -- --dev`
//! and then set the `-d http://localhost:3340` flag on this example.
Expand Down