Skip to content

Commit

Permalink
feat: integrate serde and serde_json for JSON serialization in worksp…
Browse files Browse the repository at this point in the history
…ace example
  • Loading branch information
katopz committed Feb 26, 2025
1 parent d856b71 commit b98f484
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 8 deletions.
91 changes: 91 additions & 0 deletions examples/r5/workspace-example/Cargo.lock

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

6 changes: 5 additions & 1 deletion examples/r5/workspace-example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
members = [
"utils",
"foo"
]
]

[workspace.dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
2 changes: 2 additions & 0 deletions examples/r5/workspace-example/foo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ edition = "2021"

[dependencies]
utils = { path = "../utils" }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
4 changes: 2 additions & 2 deletions examples/r5/workspace-example/foo/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use utils::add;
use utils::bar::add;

fn main() {
println!("{:?}", add(1, 2));
println!("{:?}", serde_json::to_string(&add(1, 2)).unwrap());
}
2 changes: 2 additions & 0 deletions examples/r5/workspace-example/utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ version = "0.1.0"
edition = "2021"

[dependencies]
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
12 changes: 12 additions & 0 deletions examples/r5/workspace-example/utils/src/bar.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
pub struct AddResponse {
pub output: u64,
}

pub fn add(left: u64, right: u64) -> AddResponse {
AddResponse {
output: left + right,
}
}
9 changes: 4 additions & 5 deletions examples/r5/workspace-example/utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
pub fn add(left: u64, right: u64) -> u64 {
left + right
}
pub mod bar;
pub use bar::*;

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
let result = bar::add(2, 2);
assert_eq!(result.output, 4);
}
}

0 comments on commit b98f484

Please sign in to comment.