feat: generate with serializers
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
@@ -12,3 +12,4 @@ tracing.workspace = true
|
||||
tokio.workspace = true
|
||||
tracing-subscriber.workspace = true
|
||||
anyhow.workspace = true
|
||||
prost.workspace = true
|
||||
|
@@ -0,0 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package basic.includes.my_include;
|
||||
|
||||
message MyInclude {
|
||||
string name = 1;
|
||||
}
|
@@ -1,7 +1,10 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package test.can.generate.output.rust;
|
||||
import "includes/my_include.proto";
|
||||
|
||||
package basic.my_event;
|
||||
|
||||
message MyEvent {
|
||||
string name = 1;
|
||||
basic.includes.my_include.MyInclude include = 2;
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct MyEvent {
|
||||
pub struct MyInclude {
|
||||
#[prost(string, tag="1")]
|
||||
pub name: std::string::String,
|
||||
}
|
7
examples/basic-setup/src/crunch/basic.my_event.rs
Normal file
7
examples/basic-setup/src/crunch/basic.my_event.rs
Normal file
@@ -0,0 +1,7 @@
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct MyEvent {
|
||||
#[prost(string, tag="1")]
|
||||
pub name: std::string::String,
|
||||
#[prost(message, optional, tag="2")]
|
||||
pub include: ::std::option::Option<super::includes::my_include::MyInclude>,
|
||||
}
|
@@ -1 +1,58 @@
|
||||
pub mod test_can_generate_output_rust { include!("test.can.generate.output.rust.rs"); }
|
||||
pub mod basic {
|
||||
pub mod my_event {
|
||||
include!("basic.my_event.rs");
|
||||
|
||||
impl ::crunch::Serializer for MyEvent {
|
||||
fn serialize(&self) -> Result<Vec<u8>, ::crunch::errors::SerializeError> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
impl ::crunch::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",
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pub mod includes {
|
||||
pub mod my_include {
|
||||
include!("basic.includes.my_include.rs");
|
||||
|
||||
impl ::crunch::Serializer for MyInclude {
|
||||
fn serialize(&self) -> Result<Vec<u8>, ::crunch::errors::SerializeError> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
impl ::crunch::Deserializer for MyInclude {
|
||||
fn deserialize(_raw: Vec<u8>) -> Result<Self, ::crunch::errors::DeserializeError>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl Event for MyInclude {
|
||||
fn event_info() -> ::crunch::traits::EventInfo {
|
||||
EventInfo {
|
||||
domain: "my-domain",
|
||||
entity_type: "my-entity-type",
|
||||
event_name: "my-event-name",
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,14 +1,16 @@
|
||||
use crunch::traits::{Deserializer, Event, EventInfo, Serializer};
|
||||
mod crunch;
|
||||
|
||||
use ::crunch::traits::{Deserializer, Event, EventInfo, Serializer};
|
||||
|
||||
struct MyEvent {}
|
||||
|
||||
impl Serializer for MyEvent {
|
||||
fn serialize(&self) -> Result<Vec<u8>, crunch::errors::SerializeError> {
|
||||
fn serialize(&self) -> Result<Vec<u8>, ::crunch::errors::SerializeError> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
impl Deserializer for MyEvent {
|
||||
fn deserialize(_raw: Vec<u8>) -> Result<Self, crunch::errors::DeserializeError>
|
||||
fn deserialize(_raw: Vec<u8>) -> Result<Self, ::crunch::errors::DeserializeError>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
@@ -17,7 +19,7 @@ impl Deserializer for MyEvent {
|
||||
}
|
||||
|
||||
impl Event for MyEvent {
|
||||
fn event_info() -> crunch::traits::EventInfo {
|
||||
fn event_info() -> ::crunch::traits::EventInfo {
|
||||
EventInfo {
|
||||
domain: "my-domain",
|
||||
entity_type: "my-entity-type",
|
||||
@@ -28,7 +30,14 @@ impl Event for MyEvent {
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
let crunch = crunch::builder::Builder::default().build()?;
|
||||
crunch::basic::my_event::MyEvent {
|
||||
name: "some-name".into(),
|
||||
include: Some(crunch::basic::includes::my_include::MyInclude {
|
||||
name: "some-name".into(),
|
||||
}),
|
||||
};
|
||||
|
||||
let crunch = ::crunch::builder::Builder::default().build()?;
|
||||
|
||||
crunch
|
||||
.subscribe(|_item: MyEvent| async move { Ok(()) })
|
||||
|
Reference in New Issue
Block a user