Skip to content

Commit

Permalink
add serde events
Browse files Browse the repository at this point in the history
  • Loading branch information
DougAnderson444 committed Jan 10, 2024
1 parent 64a0430 commit 316e2d7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
12 changes: 9 additions & 3 deletions crates/seed-keeper-wit-ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ name = "seed-keeper-wit-ui"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
crate-type = ["cdylib"]

[dependencies]
cargo-component-bindings = { workspace = true }
wurbo = "0.1.2"

[lib]
crate-type = ["cdylib"]
# optional dependencies
serde = { version = "1.0", optional = true, features = ["derive"] }
serde_json = { version = "1.0.107", optional = true }

[features]
default = ["serde"]
serde = ["dep:serde", "dep:serde_json"]

[package.metadata.component]
package = "seed-keeper:wit-ui"
Expand Down
26 changes: 26 additions & 0 deletions crates/seed-keeper-wit-ui/src/events.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//! Events which can be emitted from this component.
//! Match on the received json string to listen for these events.
/// Events which can be emitted from this component.
/// If the `serde` feature is enabled, these events will be serialized
/// with an adjacent `tag` and `val` to match the style that wit-component uses,
/// so that when this event reaches the Context Router in `wurbo`, it can be routed accordingly.
/// See <https://serde.rs/enum-representations.html#adjacently-tagged> for more information.
///
/// This enum is non-exhaustive, so that new events can be added in the future without breaking
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(tag = "tag", content = "val"))]
#[non_exhaustive]
pub enum Contexts {
Events(Event),
}

#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(tag = "tag", content = "val"))]
#[non_exhaustive]
pub enum Event {
/// The encrypted seed
Encrypted(Vec<u8>),
}
2 changes: 2 additions & 0 deletions crates/seed-keeper-wit-ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//!
cargo_component_bindings::generate!();

/// Event types which can can emitted from this UI
pub mod events;
mod input;
mod output;
mod page;
Expand Down

0 comments on commit 316e2d7

Please sign in to comment.