Skip to content

Commit

Permalink
chore(rs-examples): format imports consistently
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Volosatovs <[email protected]>
  • Loading branch information
rvolosatovs committed Aug 13, 2024
1 parent 4da35db commit 71682a0
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 21 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion examples/rust/echo-stream-nats-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@ clap = { workspace = true, features = [
"suggestions",
"usage",
] }
futures = { workspace = true }
tokio = { workspace = true, features = ["rt-multi-thread"] }
tracing-subscriber = { workspace = true, features = ["ansi", "fmt"] }
tracing = { workspace = true }
tracing-subscriber = { workspace = true, features = [
"ansi",
"env-filter",
"fmt",
] }
url = { workspace = true }
wit-bindgen-wrpc = { workspace = true }
wrpc-transport-nats = { workspace = true }
22 changes: 16 additions & 6 deletions examples/rust/echo-stream-nats-client/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use std::time::Duration;
use core::time::Duration;

use anyhow::Context as _;
use async_stream::stream;
use bindings::wrpc_examples::echo_stream::handler::Req;
use clap::Parser;
use tokio::{sync::mpsc, time::sleep};
use futures::StreamExt as _;
use tokio::sync::mpsc;
use tokio::time::sleep;
use tracing_subscriber::layer::SubscriberExt as _;
use tracing_subscriber::util::SubscriberInitExt as _;
use url::Url;
use wit_bindgen_wrpc::futures::StreamExt;

mod bindings {
wit_bindgen_wrpc::generate!({
Expand All @@ -16,6 +18,8 @@ mod bindings {
});
}

use bindings::wrpc_examples::echo_stream::handler::{echo, Req};

#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
Expand All @@ -30,7 +34,13 @@ struct Args {

#[tokio::main]
async fn main() -> anyhow::Result<()> {
tracing_subscriber::fmt().init();
tracing_subscriber::registry()
.with(
tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info")),
)
.with(tracing_subscriber::fmt::layer().compact().without_time())
.init();

let Args { nats, prefixes } = Args::parse();

Expand All @@ -45,7 +55,7 @@ async fn main() -> anyhow::Result<()> {
}
});
let wrpc = wrpc_transport_nats::Client::new(nats.clone(), prefix.clone(), None);
let (mut output_stream, res) = bindings::wrpc_examples::echo_stream::handler::echo(
let (mut output_stream, res) = echo(
&wrpc,
None,
Req {
Expand Down
6 changes: 5 additions & 1 deletion examples/rust/echo-stream-nats-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ clap = { workspace = true, features = [
futures = { workspace = true }
tokio = { workspace = true, features = ["rt-multi-thread", "signal"] }
tracing = { workspace = true }
tracing-subscriber = { workspace = true, features = ["ansi", "fmt"] }
tracing-subscriber = { workspace = true, features = [
"ansi",
"env-filter",
"fmt",
] }
url = { workspace = true }
wit-bindgen-wrpc = { workspace = true }
wrpc-transport-nats = { workspace = true }
16 changes: 6 additions & 10 deletions examples/rust/echo-stream-nats-server/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use core::pin::pin;
use core::pin::{pin, Pin};

use anyhow::Context as _;
use async_stream::stream;
use clap::Parser;
use futures::stream::select_all;
use futures::{StreamExt as _, TryStreamExt as _};
use futures::{Stream, StreamExt as _, TryStreamExt as _};
use tokio::{select, signal};
use tracing::{info, warn};
use url::Url;
Expand All @@ -17,6 +17,8 @@ mod bindings {
});
}

use bindings::exports::wrpc_examples::echo_stream::handler::Req;

#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
Expand All @@ -38,14 +40,8 @@ impl bindings::exports::wrpc_examples::echo_stream::handler::Handler<Option<asyn
async fn echo(
&self,
_cx: Option<async_nats::HeaderMap>,
r: bindings::exports::wrpc_examples::echo_stream::handler::Req,
) -> wit_bindgen_wrpc::anyhow::Result<
::core::pin::Pin<
::std::boxed::Box<
dyn wit_bindgen_wrpc::futures::Stream<Item = Vec<u64>> + ::core::marker::Send,
>,
>,
> {
r: Req,
) -> anyhow::Result<Pin<Box<dyn Stream<Item = Vec<u64>> + Send>>> {
let mut input_stream = r.input;
Ok(Box::pin(stream! {
while let Some(item) = input_stream.next().await {
Expand Down
2 changes: 1 addition & 1 deletion examples/rust/wasi-keyvalue-nats-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async fn main() -> anyhow::Result<()> {
Server::default(),
)
.await
.context("failed to serve `wrpc-examples.hello/handler.hello`")?;
.context("failed to serve `wasi:keyvalue/store`")?;
// NOTE: This will conflate all invocation streams into a single stream via `futures::stream::SelectAll`,
// to customize this, iterate over the returned `invocations` and set up custom handling per export
let mut invocations = select_all(invocations.into_iter().map(
Expand Down

0 comments on commit 71682a0

Please sign in to comment.