feat: add basic example

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2023-09-24 10:48:41 +02:00
parent c34ce37e6d
commit 4e70adfb38
Signed by: kjuulh
GPG Key ID: 9AA7BC13CE474394
4 changed files with 66 additions and 1 deletions

11
Cargo.lock generated
View File

@ -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"

View File

@ -1,5 +1,5 @@
[workspace]
members = ["crates/*"]
members = ["crates/*", "examples/*"]
resolver = "2"
[workspace.dependencies]

View File

@ -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

View File

@ -0,0 +1,40 @@
use crunch::traits::{Deserializer, Event, EventInfo, Serializer};
struct MyEvent {}
impl Serializer for MyEvent {
fn serialize(&self) -> Result<Vec<u8>, crunch::errors::SerializeError> {
todo!()
}
}
impl Deserializer for MyEvent {
fn deserialize(_raw: Vec<u8>) -> Result<Self, crunch::errors::DeserializeError>
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(())
}