protoflow_blocks/blocks/
sys.rs1#[cfg(not(feature = "std"))]
4pub mod sys {
5 pub trait SysBlocks {}
6 pub enum SysBlockConfig {}
7}
8
9#[cfg(feature = "std")]
10pub mod sys {
11 use super::{
12 prelude::{vec, Box, Cow, Named, String, Vec},
13 types::ByteSize,
14 BlockConnections, BlockInstantiation, InputPortName, OutputPortName, System,
15 };
16 use protoflow_core::Block;
17
18 pub trait SysBlocks {
19 fn read_dir(&mut self) -> ReadDir;
20 fn read_env(&mut self) -> ReadEnv;
21 fn read_file(&mut self) -> ReadFile;
22 fn read_stdin(&mut self) -> ReadStdin;
23 fn write_file(&mut self) -> WriteFile;
24 fn write_stderr(&mut self) -> WriteStderr;
25 fn write_stdout(&mut self) -> WriteStdout;
26 }
27
28 #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
29 #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
30 pub enum SysBlockTag {
31 ReadDir,
32 ReadEnv,
33 ReadFile,
34 ReadStdin,
35 WriteFile,
36 WriteStderr,
37 WriteStdout,
38 }
39
40 #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
41 #[derive(Clone, Debug)]
42 pub enum SysBlockConfig {
43 ReadDir {
44 path: InputPortName,
45 output: OutputPortName,
46 },
47
48 ReadEnv {
49 name: InputPortName,
50 output: OutputPortName,
51 },
52
53 ReadFile {
54 path: InputPortName,
55 output: OutputPortName,
56 },
57
58 ReadStdin {
59 output: OutputPortName,
60 buffer_size: Option<ByteSize>,
61 },
62
63 WriteFile {
64 path: InputPortName,
65 input: InputPortName,
66 flags: Option<WriteFlags>,
67 },
68
69 WriteStderr {
70 input: InputPortName,
71 },
72
73 WriteStdout {
74 input: InputPortName,
75 },
76 }
77
78 impl Named for SysBlockConfig {
79 fn name(&self) -> Cow<str> {
80 use SysBlockConfig::*;
81 Cow::Borrowed(match self {
82 ReadDir { .. } => "ReadDir",
83 ReadEnv { .. } => "ReadEnv",
84 ReadFile { .. } => "ReadFile",
85 ReadStdin { .. } => "ReadStdin",
86 WriteFile { .. } => "WriteFile",
87 WriteStderr { .. } => "WriteStderr",
88 WriteStdout { .. } => "WriteStdout",
89 })
90 }
91 }
92
93 impl BlockConnections for SysBlockConfig {
94 fn output_connections(&self) -> Vec<(&'static str, Option<OutputPortName>)> {
95 use SysBlockConfig::*;
96 match self {
97 ReadDir { output, .. }
98 | ReadEnv { output, .. }
99 | ReadFile { output, .. }
100 | ReadStdin { output, .. } => {
101 vec![("output", Some(output.clone()))]
102 }
103 WriteFile { .. } | WriteStderr { .. } | WriteStdout { .. } => vec![],
104 }
105 }
106 }
107
108 impl BlockInstantiation for SysBlockConfig {
109 fn instantiate(&self, system: &mut System) -> Box<dyn Block> {
110 use SysBlockConfig::*;
111 match self {
112 ReadDir { .. } => Box::new(super::ReadDir::with_system(system)),
113 ReadEnv { .. } => Box::new(super::ReadEnv::<String>::with_system(system)),
114 ReadFile { .. } => Box::new(super::ReadFile::with_system(system)),
115 ReadStdin { buffer_size, .. } => {
116 Box::new(super::ReadStdin::with_system(system, *buffer_size))
117 }
118 WriteFile { flags, .. } => Box::new(super::WriteFile::with_system(system, *flags)),
119 WriteStderr { .. } => Box::new(super::WriteStderr::with_system(system)),
120 WriteStdout { .. } => Box::new(super::WriteStdout::with_system(system)),
121 }
122 }
123 }
124
125 mod read_dir;
126 pub use read_dir::*;
127
128 mod read_env;
129 pub use read_env::*;
130
131 mod read_file;
132 pub use read_file::*;
133
134 mod read_stdin;
135 pub use read_stdin::*;
136
137 mod write_file;
138 pub use write_file::*;
139
140 mod write_stderr;
141 pub use write_stderr::*;
142
143 mod write_stdout;
144 pub use write_stdout::*;
145}
146
147pub use sys::*;