Skip to content

Commit e1ea0a7

Browse files
committed
Merge branch 'client_crypto_provider' of https://github.com/swimos/swim-rust into dependabot/cargo/axum-0.7.5
2 parents cf431fe + 95fcce3 commit e1ea0a7

File tree

664 files changed

+2755
-1131
lines changed

Some content is hidden

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

664 files changed

+2755
-1131
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,5 +140,5 @@ jobs:
140140
- name: Upload to codecov.io
141141
uses: codecov/codecov-action@v4
142142
with:
143-
token: ${{secrets.CODECOV_TOKEN}}
143+
token: ${{ secrets.CODECOV_TOKEN }}
144144
fail_ci_if_error: true

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@
88
!/demos/**/Cargo.lock
99

1010
**/.DS_Store
11-
*.iml
11+
*.iml
12+
13+
# Code coverage files
14+
*.profraw

.tarpaulin.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ exclude = [
3232
"swimos_form_derive",
3333
"swimos_agent_derive",
3434
"macro_utilities",
35+
"example_client_2_2",
36+
"example_server_2_2",
37+
"example_client_2_3",
38+
"example_server_2_3"
3539
]
3640
workspace = true
3741
avoid-cfg-tarpaulin = true

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ members = [
4040
"example_apps/join_value",
4141
"example_apps/aggregations",
4242
"example_apps/time_series",
43+
"example_apps/devguide/2_2/*",
44+
"example_apps/devguide/2_3/*",
4345
]
4446

4547
exclude = [
@@ -119,7 +121,7 @@ regex = "1.3.6"
119121
fnv = "1.0.7"
120122
cursive = { default-features = false, version = "0.20" }
121123
duration-str = "0.11.2"
122-
quick-xml = "0.33.0"
124+
quick-xml = "0.34.0"
123125
csv = "1.2"
124126
serde-xml-rs = "0.6"
125127
axum = "0.7.5"

DEVELOPMENT.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# SwimOS Development Guid
2+
3+
## Dependencies
4+
[Formatting](https://github.com/rust-lang/rustfmt): `rustup component add rustfmt`<br>
5+
[Clippy](https://github.com/rust-lang/rust-clippy): `rustup component add clippy`<br>
6+
[Tarpaulin](https://github.com/xd009642/tarpaulin) `cargo install cargo-tarpaulin`<br>
7+
8+
## Unit tests
9+
#### Basic: `cargo test`
10+
#### With coverage: `cargo tarpaulin --ignore-tests -o Html -t 300`
11+
12+
## Lint
13+
#### Manual
14+
1) `cargo fmt --all -- --check`
15+
2) `cargo clippy --all-features --workspace --all-targets -- -D warnings`
16+
17+
#### Automatic (before commit):
18+
- Install hook: `sh ./install-commit-hook.sh`
19+
- Remove hook: `sh ./remove-commit-hook.sh`
20+
21+
Note: The pre-commit hooks take a while to run all checks.

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@
176176

177177
END OF TERMS AND CONDITIONS
178178

179-
Copyright 2023 Swim Inc.
179+
Copyright 2024 Swim Inc.
180180

181181
Licensed under the Apache License, Version 2.0 (the "License");
182182
you may not use this file except in compliance with the License.

README.md

Lines changed: 90 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,21 @@
33
<a href="https://www.swimos.org"><img src="https://docs.swimos.org/readme/marlin-blue.svg" align="left"></a>
44
<br><br><br><br>
55

6-
## ⚠️🚧 Warning: Project is still under construction 👷 🚧
6+
The Swim Rust SDK contains software framework for building stateful applications that can be interacted
7+
with via multiplexed streaming APIs. It is built on top of the [Tokio asynchronous runtime](https://tokio.rs/)
8+
and a Tokio runtime is required for any Swim application.
79

8-
This project is still in its early stages of development, meaning that it is not yet stable and is subject to frequent API changes.
10+
Each application consists of some number of stateful agents, each of which runs as a separate Tokio task
11+
and can be individually addressed by a URI. An agent may have both public and private state which can either
12+
be held solely in memory or, optionally, in persistent storage. The public state of the agent consists of a
13+
number of lanes, analogous to a field in a record. There are multiple kinds of lanes that, for example, lanes
14+
containing single values and those containing a map of key-value pairs.
915

10-
**USE AT YOUR OWN RISK!**
16+
The state of any lane can be observed by establishing a link to it (either from another agent instance or a
17+
dedicated client). A established link will push all updates to the state of that lane to the subscriber and
18+
will also allow the subscriber to request changes to the state (for lane kinds that support this). Links
19+
operate over a web-socket connection and are multiplexed, meaning that links to multiple lanes on the same
20+
host can share a single web-socket connection.
1121

1222
## Usage Guides
1323

@@ -17,25 +27,85 @@ This project is still in its early stages of development, meaning that it is not
1727

1828
## Examples
1929

20-
TODO
21-
## Development
30+
The following example application runs a SwimOS server that hosts a single agent route where each agent instance
31+
has single lane, called `lane`. Each time a changes is made to the lane, it will be printed on the console by the
32+
server.
33+
34+
```rust
35+
use swimos::{
36+
agent::{
37+
agent_lifecycle::HandlerContext,
38+
agent_model::AgentModel,
39+
event_handler::{EventHandler, HandlerActionExt},
40+
lanes::ValueLane,
41+
lifecycle, AgentLaneModel,
42+
},
43+
route::RoutePattern,
44+
server::{until_termination, Server, ServerBuilder},
45+
};
46+
47+
#[tokio::main]
48+
pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
49+
50+
// An agent route consists of the agent definition and a lifecycle.
51+
let model = AgentModel::new(ExampleAgent::default, ExampleLifecycle.into_lifecycle());
52+
53+
let server = ServerBuilder::with_plane_name("Example Plane")
54+
.set_bind_addr("127.0.0.1:8080".parse()?) // Bind the server to this address.
55+
.add_route(RoutePattern::parse_str("/examples/{id}")?, model) // Register the agent we have defined.
56+
.build()
57+
.await?;
58+
59+
// Run the server until we terminate it with Ctrl-C.
60+
let (task, handle) = server.run();
61+
let (ctrl_c_result, server_result) = tokio::join!(until_termination(handle, None), task);
2262

23-
### Dependencies
24-
[Formatting](https://github.com/rust-lang/rustfmt): `rustup component add rustfmt`<br>
25-
[Clippy](https://github.com/rust-lang/rust-clippy): `rustup component add clippy`<br>
26-
[Tarpaulin](https://github.com/xd009642/tarpaulin) `cargo install cargo-tarpaulin`<br>
63+
ctrl_c_result?;
64+
server_result?;
65+
Ok(())
66+
}
2767

28-
### Unit tests
29-
##### Basic: `cargo test`
30-
##### With coverage: `cargo tarpaulin --ignore-tests -o Html -t 300`
68+
// Deriving the `AgentLaneModel` trait makes this type into an agent.
69+
#[derive(AgentLaneModel)]
70+
struct ExampleAgent {
71+
lane: ValueLane<i32>,
72+
}
3173

32-
### Lint
33-
##### Manual
34-
1) `cargo fmt --all -- --check`
35-
2) `cargo clippy --all-features --workspace --all-targets -- -D warnings`
74+
// Any agent type can have any number of lifecycles defined for it. A lifecycle describes
75+
// how the agent will react to events that occur as it executes.
76+
#[derive(Default, Clone, Copy)]
77+
struct ExampleLifecycle;
3678

37-
##### Automatic (before commit):
38-
- Install hook: `sh ./install-commit-hook.sh`
39-
- Remove hook: `sh ./remove-commit-hook.sh`
79+
// The `lifecycle` macro creates an method called `into_lifecycle` for the type, using the
80+
// annotated event handlers methods in the block.
81+
#[lifecycle(ExampleAgent)]
82+
impl ExampleLifecycle {
83+
84+
#[on_event(lane)]
85+
fn lane_event(
86+
&self,
87+
context: HandlerContext<ExampleAgent>,
88+
value: &i32,
89+
) -> impl EventHandler<ExampleAgent> {
90+
let n = *value;
91+
context.get_agent_uri().and_then(move |uri| {
92+
context.effect(move || {
93+
println!("Received value: {} for 'lane' on agent at URI: {}.", n, uri);
94+
})
95+
})
96+
}
97+
98+
}
99+
```
100+
101+
For example, if a Swim client sends an update, with the value `5`, to the agent at the URI `/examples/name` for the
102+
lane `lane`, an instance of `ExampleAgent`, using `ExampleLifecycle`, will be started by the server. The value of the
103+
lane will then be set to `5` and the following will be printed on the console:
104+
105+
```
106+
Received value: 5 for 'lane' on agent at URI: /examples/name.
107+
```
108+
109+
## Development
40110

41-
Note: The pre-commit hooks take a while to run all checks.
111+
See the [development guide](DEVELOPMENT.md).

api/formats/swimos_msgpack/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2015-2023 Swim Inc.
1+
// Copyright 2015-2024 Swim Inc.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

api/formats/swimos_msgpack/src/reader/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2015-2023 Swim Inc.
1+
// Copyright 2015-2024 Swim Inc.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

api/formats/swimos_msgpack/src/reader/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2015-2023 Swim Inc.
1+
// Copyright 2015-2024 Swim Inc.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)