protoflow_blocks/blocks/
hash.rs1#[cfg(not(feature = "hash"))]
4pub mod hash {
5 pub trait HashBlocks {}
6 pub enum HashBlockConfig {}
7}
8
9#[cfg(feature = "hash")]
10pub mod hash {
11 use super::{
12 prelude::{vec, Box, Cow, Named, Vec},
13 types::HashAlgorithm,
14 BlockConnections, BlockInstantiation, InputPortName, OutputPortName, System,
15 };
16 use protoflow_core::Block;
17
18 pub trait HashBlocks {
19 fn hash_blake3(&mut self) -> Hash;
20 }
21
22 #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
23 #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
24 pub enum HashBlockTag {
25 Hash,
26 }
27
28 #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
29 #[derive(Clone, Debug)]
30 pub enum HashBlockConfig {
31 Hash {
32 input: InputPortName,
33 output: Option<OutputPortName>,
34 hash: OutputPortName,
35 algorithm: Option<HashAlgorithm>,
36 },
37 }
38
39 impl Named for HashBlockConfig {
40 fn name(&self) -> Cow<str> {
41 use HashBlockConfig::*;
42 Cow::Borrowed(match self {
43 Hash { .. } => "Hash",
44 })
45 }
46 }
47
48 impl BlockConnections for HashBlockConfig {
49 fn output_connections(&self) -> Vec<(&'static str, Option<OutputPortName>)> {
50 use HashBlockConfig::*;
51 match self {
52 Hash { output, hash, .. } => {
53 vec![("output", output.clone()), ("hash", Some(hash.clone()))]
54 }
55 }
56 }
57 }
58
59 impl BlockInstantiation for HashBlockConfig {
60 fn instantiate(&self, system: &mut System) -> Box<dyn Block> {
61 use HashBlockConfig::*;
62 match self {
63 Hash { algorithm, .. } => Box::new(super::Hash::with_system(system, *algorithm)),
64 }
65 }
66 }
67
68 mod hash;
69 pub use hash::*;
70}
71
72pub use hash::*;