macro_rules! crud {
(
$crud_type:ident, $i:ident, $path:expr, $get_peers:ident, $signal_type:ident
) => { ... };
}
Expand description
A macro to go quick and easy from having just a Holochain entry definition to having a full create-read-update-delete set of functionality in your Zome, “signals” (events), as well as time based indexing and queries. See example for a comprehensive look at how this works.
ⓘ
use hdk::prelude::*;
use hdk_crud::*;
#[hdk_entry(id = "example")]
#[derive(Clone, PartialEq)]
pub struct Example {
pub number: i32,
}
// TestSignal pops out of the crud! macro
#[derive(Debug, Serialize, Deserialize, SerializedBytes)]
#[serde(untagged)]
pub enum SignalTypes {
Example(ActionSignal<Example>),
}
impl From<ActionSignal<Example>> for SignalTypes {
fn from(value: ActionSignal<Example>) -> Self {
SignalTypes::Example(value)
}
}
pub fn recv_remote_signal(signal: ExternIO) -> ExternResult<()> {
Ok(emit_signal(&signal)?)
}
pub fn get_peers() -> ExternResult<Vec<AgentPubKey>> {
Ok(Vec::new())
}
crud!(
Example,
example,
"example",
get_peers,
SignalTypes
);