From 4e70adfb38e634c9a51daa0d3bd54b32548f9528 Mon Sep 17 00:00:00 2001 From: kjuulh Date: Sun, 24 Sep 2023 10:48:41 +0200 Subject: [PATCH] feat: add basic example Signed-off-by: kjuulh --- Cargo.lock | 11 +++++++++ Cargo.toml | 2 +- examples/basic-setup/Cargo.toml | 14 +++++++++++ examples/basic-setup/src/main.rs | 40 ++++++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 examples/basic-setup/Cargo.toml create mode 100644 examples/basic-setup/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index bfd1d99..a62b81a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -140,6 +140,17 @@ version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6b4d9b1225d28d360ec6a231d65af1fd99a2a095154c8040689617290569c5c" +[[package]] +name = "basic-setup" +version = "0.1.0" +dependencies = [ + "anyhow", + "crunch", + "tokio", + "tracing", + "tracing-subscriber", +] + [[package]] name = "bitflags" version = "1.3.2" diff --git a/Cargo.toml b/Cargo.toml index d3292e5..11ad75a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = ["crates/*"] +members = ["crates/*", "examples/*"] resolver = "2" [workspace.dependencies] diff --git a/examples/basic-setup/Cargo.toml b/examples/basic-setup/Cargo.toml new file mode 100644 index 0000000..e1e7789 --- /dev/null +++ b/examples/basic-setup/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "basic-setup" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +crunch = { workspace = true,default-features = false, features = ["in-memory"] } + +tracing.workspace = true +tokio.workspace = true +tracing-subscriber.workspace = true +anyhow.workspace = true diff --git a/examples/basic-setup/src/main.rs b/examples/basic-setup/src/main.rs new file mode 100644 index 0000000..8cf8a70 --- /dev/null +++ b/examples/basic-setup/src/main.rs @@ -0,0 +1,40 @@ +use crunch::traits::{Deserializer, Event, EventInfo, Serializer}; + +struct MyEvent {} + +impl Serializer for MyEvent { + fn serialize(&self) -> Result, crunch::errors::SerializeError> { + todo!() + } +} +impl Deserializer for MyEvent { + fn deserialize(_raw: Vec) -> Result + where + Self: Sized, + { + todo!() + } +} + +impl Event for MyEvent { + fn event_info() -> crunch::traits::EventInfo { + EventInfo { + domain: "my-domain", + entity_type: "my-entity-type", + event_name: "my-event-name", + } + } +} + +#[tokio::main] +async fn main() -> anyhow::Result<()> { + let crunch = crunch::builder::Builder::default().build()?; + + crunch + .subscribe(|_item: MyEvent| async move { Ok(()) }) + .await?; + + crunch.publish(MyEvent {}).await?; + + Ok(()) +}