1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// This is free and unencumbered software released into the public domain.

#![no_std]
#![deny(unsafe_code)]

#[doc(hidden)]
pub use protoflow_core::prelude;

mod core;
pub use core::*;

mod encoding;
pub use encoding::*;

mod flow;
pub use flow::*;

#[cfg(not(feature = "hash"))]
pub trait HashBlocks {}

#[cfg(feature = "hash")]
mod hash;
#[cfg(feature = "hash")]
pub use hash::*;

mod io;
pub use io::*;

mod math;
pub use math::*;

#[cfg(feature = "std")]
mod stdio;
#[cfg(feature = "std")]
pub use stdio::*;

#[cfg(not(feature = "std"))]
pub trait SysBlocks {}

#[cfg(feature = "std")]
mod sys;
#[cfg(feature = "std")]
pub use sys::*;

mod system;
pub use system::*;

mod text;
pub use text::*;

pub use protoflow_core::{SystemBuilding, SystemExecution};

pub trait AllBlocks:
    CoreBlocks + FlowBlocks + HashBlocks + IoBlocks + MathBlocks + SysBlocks + TextBlocks
{
}

/// The set of block types that are enabled in this build of the crate.
#[doc(hidden)]
pub static BLOCKS: &[(&str, &str)] = &[
    // CoreBlocks
    ("core", "Buffer"),
    ("core", "Const"),
    ("core", "Count"),
    ("core", "Delay"),
    ("core", "Drop"),
    ("core", "Random"),
    // FlowBlocks
    // HashBlocks
    #[cfg(feature = "hash")]
    ("hash", "Hash"),
    // IoBlocks
    ("io", "Decode"),
    ("io", "Encode"),
    ("io", "EncodeHex"),
    // MathBlocks
    // SysBlocks
    #[cfg(feature = "std")]
    ("sys", "ReadDir"),
    #[cfg(feature = "std")]
    ("sys", "ReadEnv"),
    #[cfg(feature = "std")]
    ("sys", "ReadFile"),
    #[cfg(feature = "std")]
    ("sys", "ReadStdin"),
    #[cfg(feature = "std")]
    ("sys", "WriteFile"),
    #[cfg(feature = "std")]
    ("sys", "WriteStderr"),
    #[cfg(feature = "std")]
    ("sys", "WriteStdout"),
    // TextBlocks
];

#[cfg(feature = "std")]
#[doc(hidden)]
pub fn build_stdio_system(
    system_name: prelude::String,
    config: StdioConfig,
) -> Result<System, StdioError> {
    use prelude::String;
    Ok(match system_name.as_ref() {
        // CoreBlocks
        "Buffer" => Buffer::<String>::build_system(config)?,
        "Const" => Const::<String>::build_system(config)?,
        "Count" => Count::<String>::build_system(config)?,
        "Delay" => Delay::<String>::build_system(config)?,
        "Drop" => Drop::<String>::build_system(config)?,
        "Random" => Random::<u64>::build_system(config)?,
        // FlowBlocks
        // HashBlocks
        #[cfg(feature = "hash")]
        "Hash" => Hash::build_system(config)?,
        // IoBlocks
        "Decode" => Decode::build_system(config)?,
        "Encode" => Encode::build_system(config)?,
        "EncodeHex" => EncodeHex::build_system(config)?,
        // MathBlocks
        // SysBlocks
        "ReadDir" => ReadDir::build_system(config)?,
        "ReadEnv" => ReadEnv::<String>::build_system(config)?,
        "ReadFile" => ReadFile::build_system(config)?,
        "ReadStdin" => ReadStdin::build_system(config)?,
        "WriteFile" => WriteFile::build_system(config)?,
        "WriteStderr" => WriteStderr::build_system(config)?,
        "WriteStdout" => WriteStdout::build_system(config)?,
        // TextBlocks
        _ => return Err(StdioError::UnknownSystem(system_name))?,
    })
}