Skip to content

Commit 4b7f89a

Browse files
authored
Merge pull request #583 from swimos/transit
Adds rust port of the transit app to the examples.
2 parents b2c8816 + 63980dd commit 4b7f89a

File tree

75 files changed

+3928
-103
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+3928
-103
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ members = [
3131
"example_apps/map_downlink",
3232
"example_apps/local_downlink",
3333
"example_apps/http_lane",
34+
"example_apps/transit",
35+
"example_apps/transit/transit-model",
3436
"example_apps/tutorial_app",
3537
"example_apps/tutorial_app/model",
3638
"example_apps/tutorial_app/generator",
@@ -71,6 +73,7 @@ nom = "7.1"
7173
nom_locate = "4.0"
7274
tracing = "0.1"
7375
tracing-subscriber = "0.3"
76+
tracing-appender = "0.2"
7477
base64 = "0.13"
7578
num-traits = "0.2"
7679
thiserror = "1.0"
@@ -103,5 +106,6 @@ percent-encoding = "2.1.0"
103106
mime = "0.3"
104107
serde_json = "1.0"
105108
serde = "1.0"
109+
reqwest = "0.11"
106110
convert_case = "0.6"
107111
frunk = "0.4"

example_apps/command_lane/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ mod agent;
2727
mod model;
2828

2929
#[tokio::main]
30-
async fn main() -> Result<(), Box<dyn Error>> {
30+
async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
3131
example_logging()?;
3232
let route = RoutePattern::parse_str("/example/:name}")?;
3333

example_apps/demand_lane/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::agent::{ExampleAgent, ExampleLifecycle};
2626
mod agent;
2727

2828
#[tokio::main]
29-
async fn main() -> Result<(), Box<dyn Error>> {
29+
async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
3030
example_logging()?;
3131
let route = RoutePattern::parse_str("/example/:name}")?;
3232

example_apps/demand_map_lane/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::agent::{ExampleAgent, ExampleLifecycle};
2626
mod agent;
2727

2828
#[tokio::main]
29-
async fn main() -> Result<(), Box<dyn Error>> {
29+
async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
3030
example_logging()?;
3131
let route = RoutePattern::parse_str("/example/:name}")?;
3232

example_apps/event_downlink/src/consumer/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use self::agent::{ConsumerAgent, ConsumerLifecycle};
2525
mod agent;
2626
mod model;
2727

28-
pub async fn make_server(producer_port: u16) -> Result<BoxServer, Box<dyn Error>> {
28+
pub async fn make_server(producer_port: u16) -> Result<BoxServer, Box<dyn Error + Send + Sync>> {
2929
let route = RoutePattern::parse_str("/consumer/:name}")?;
3030

3131
let lifecycle_fn = move || ConsumerLifecycle::new(producer_port).into_lifecycle();

example_apps/event_downlink/src/main.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ mod consumer;
2222
mod producer;
2323

2424
#[tokio::main]
25-
async fn main() -> Result<(), Box<dyn Error>> {
25+
async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
2626
example_logging()?;
2727

2828
let server = producer::make_server().await?;
@@ -43,7 +43,9 @@ async fn main() -> Result<(), Box<dyn Error>> {
4343
Ok(())
4444
}
4545

46-
async fn start_consumer(rx: oneshot::Receiver<StartDependent>) -> Result<(), Box<dyn Error>> {
46+
async fn start_consumer(
47+
rx: oneshot::Receiver<StartDependent>,
48+
) -> Result<(), Box<dyn Error + Send + Sync>> {
4749
let StartDependent { bound, request } = rx.await?;
4850
let server = consumer::make_server(bound.port()).await?;
4951
let (task, handle) = server.run();

example_apps/event_downlink/src/producer/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use swim::{
2323

2424
mod agent;
2525

26-
pub async fn make_server() -> Result<BoxServer, Box<dyn Error>> {
26+
pub async fn make_server() -> Result<BoxServer, Box<dyn Error + Send + Sync>> {
2727
let route = RoutePattern::parse_str("/producer/:name}")?;
2828

2929
let lifecycle = ProducerLifecycle;

example_apps/example_util/src/lib.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -136,20 +136,24 @@ pub async fn manage_producer_and_consumer(
136136
}
137137
}
138138

139-
pub fn example_logging() -> Result<(), Box<dyn std::error::Error>> {
139+
pub fn example_filter() -> Result<EnvFilter, Box<dyn std::error::Error + Send + Sync>> {
140+
let filter = if let Ok(filter) = EnvFilter::try_from_default_env() {
141+
filter
142+
} else {
143+
EnvFilter::new("")
144+
.add_directive("swim_server_app=trace".parse()?)
145+
.add_directive("swim_runtime=trace".parse()?)
146+
.add_directive("swim_agent=trace".parse()?)
147+
.add_directive("swim_messages=trace".parse()?)
148+
.add_directive("swim_remote=trace".parse()?)
149+
};
150+
Ok(filter)
151+
}
152+
153+
pub fn example_logging() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
140154
let args = std::env::args().collect::<Vec<_>>();
141155
if args.get(1).map(String::as_str) == Some("--enable-logging") {
142-
let filter = if let Ok(filter) = EnvFilter::try_from_default_env() {
143-
filter
144-
} else {
145-
EnvFilter::new("")
146-
.add_directive("swim_server_app=trace".parse()?)
147-
.add_directive("swim_runtime=trace".parse()?)
148-
.add_directive("swim_agent=trace".parse()?)
149-
.add_directive("swim_messages=trace".parse()?)
150-
.add_directive("swim_remote=trace".parse()?)
151-
.add_directive(LevelFilter::WARN.into())
152-
};
156+
let filter = example_filter()?.add_directive(LevelFilter::WARN.into());
153157
tracing_subscriber::fmt().with_env_filter(filter).init();
154158
}
155159
Ok(())

example_apps/http_lane/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::agent::{ExampleAgent, ExampleLifecycle};
2626
mod agent;
2727

2828
#[tokio::main]
29-
async fn main() -> Result<(), Box<dyn Error>> {
29+
async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
3030
example_logging()?;
3131

3232
let route = RoutePattern::parse_str("/example/:name}")?;

example_apps/local_downlink/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ mod consumer;
3030
mod producer;
3131

3232
#[tokio::main]
33-
async fn main() -> Result<(), Box<dyn Error>> {
33+
async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
3434
example_logging()?;
3535

3636
let producer_route = RoutePattern::parse_str("/producer/:name}")?;

0 commit comments

Comments
 (0)