Skip to content

Commit

Permalink
JsJson implementation for unit type
Browse files Browse the repository at this point in the history
  • Loading branch information
sfisol committed Jul 10, 2024
1 parent 0943788 commit 3237f79
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2024-02-28
toolchain: nightly-2024-07-01
target: wasm32-unknown-unknown
components: clippy
override: true
Expand All @@ -74,7 +74,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2024-02-28
toolchain: nightly-2024-07-01
target: wasm32-unknown-unknown
components: clippy
override: true
Expand All @@ -85,7 +85,7 @@ jobs:
- name: vertigo-cli
run: |
cargo build --release -p vertigo-cli
rustup default nightly-2024-02-28
rustup default nightly-2024-07-01
mkdir ../vertigo-cli-test
mv target/release/vertigo ../vertigo-cli-test
cd ../vertigo-cli-test
Expand Down
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* `Reactive` trait that allows generic components to be more flexible with props
* `BTreeMap` and `chrono::DateTime<Utc>` support in `AutoJsJson`
* `#[js_json(default = "None")]` attribute to `AutoJsJson`
* `JsJson` implementation for unit type `()`
* All http methods in `FetchMethod`
* `history_replace` method in `Driver`
* vertigo-cli: `add-watch-path` to `watch` command
Expand Down
19 changes: 19 additions & 0 deletions crates/vertigo/src/driver_module/js_value/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,25 @@ impl JsJsonDeserialize for bool {
}
}

impl JsJsonSerialize for () {
fn to_json(self) -> JsJson {
JsJson::Object(HashMap::default())
}
}

impl JsJsonDeserialize for () {
fn from_json(context: JsJsonContext, json: JsJson) -> Result<Self, JsJsonContext> {
let map = json.get_hashmap(&context)?;

if !map.is_empty() {
let message = "Empty {} expected, inner content received".to_string();
return Err(context.add(message))
}

Ok(())
}
}

impl JsJsonSerialize for &str {
fn to_json(self) -> JsJson {
JsJson::String(self.into())
Expand Down

0 comments on commit 3237f79

Please sign in to comment.