feat: with complete example and generated code
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct MyInclude {
|
||||
#[prost(string, tag="1")]
|
||||
pub name: std::string::String,
|
||||
}
|
7
examples/basic-setup/src/gencrunch/basic.my_event.rs
Normal file
7
examples/basic-setup/src/gencrunch/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>,
|
||||
}
|
60
examples/basic-setup/src/gencrunch/mod.rs
Normal file
60
examples/basic-setup/src/gencrunch/mod.rs
Normal file
@@ -0,0 +1,60 @@
|
||||
pub mod basic {
|
||||
pub mod includes {
|
||||
pub mod my_include { use prost::Message;
|
||||
include!("basic.includes.my_include.rs");
|
||||
|
||||
impl ::crunch::traits::Serializer for MyInclude {
|
||||
fn serialize(&self) -> Result<Vec<u8>, ::crunch::errors::SerializeError> {
|
||||
Ok(self.encode_to_vec())
|
||||
}
|
||||
}
|
||||
impl ::crunch::traits::Deserializer for MyInclude {
|
||||
fn deserialize(raw: Vec<u8>) -> Result<Self, ::crunch::errors::DeserializeError>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
let output = Self::decode(raw.as_slice()).map_err(|e| ::crunch::errors::DeserializeError::ProtoErr(e))?;
|
||||
Ok(output)
|
||||
}
|
||||
}
|
||||
|
||||
impl crunch::traits::Event for MyInclude {
|
||||
fn event_info() -> ::crunch::traits::EventInfo {
|
||||
::crunch::traits::EventInfo {
|
||||
domain: "my-domain",
|
||||
entity_type: "my-entity-type",
|
||||
event_name: "my-event-name",
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pub mod my_event { use prost::Message;
|
||||
include!("basic.my_event.rs");
|
||||
|
||||
impl ::crunch::traits::Serializer for MyEvent {
|
||||
fn serialize(&self) -> Result<Vec<u8>, ::crunch::errors::SerializeError> {
|
||||
Ok(self.encode_to_vec())
|
||||
}
|
||||
}
|
||||
impl ::crunch::traits::Deserializer for MyEvent {
|
||||
fn deserialize(raw: Vec<u8>) -> Result<Self, ::crunch::errors::DeserializeError>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
let output = Self::decode(raw.as_slice()).map_err(|e| ::crunch::errors::DeserializeError::ProtoErr(e))?;
|
||||
Ok(output)
|
||||
}
|
||||
}
|
||||
|
||||
impl crunch::traits::Event for MyEvent {
|
||||
fn event_info() -> ::crunch::traits::EventInfo {
|
||||
::crunch::traits::EventInfo {
|
||||
domain: "my-domain",
|
||||
entity_type: "my-entity-type",
|
||||
event_name: "my-event-name",
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user