pub struct ReadEnv<T: Message + FromStr = String> {
pub name: InputPort<String>,
pub output: OutputPort<T>,
}Expand description
A block that reads the value of an environment variable.
§Block Diagram
block-beta
columns 4
Config space:3
space:4
space:4
ReadEnv space:2 Sink
Config-- "name" -->ReadEnv
ReadEnv-- "output" -->Sink
classDef block height:48px,padding:8px;
classDef hidden visibility:none;
class ReadEnv block
class Config hidden
class Sink hidden
§Sequence Diagram
sequenceDiagram
autonumber
participant BlockA as Another block
participant ReadEnv.name as ReadEnv.name port
participant ReadEnv as ReadEnv block
participant ReadEnv.output as ReadEnv.output port
participant BlockB as Another block
BlockA-->>ReadEnv: Connect
BlockA->>ReadEnv: Message (e.g. "TERM")
ReadEnv-->>ReadEnv.name: Close
ReadEnv-->>BlockA: Disconnect
ReadEnv-->>BlockB: Connect
ReadEnv->>ReadEnv: Read environment variable
ReadEnv->>BlockB: Message (e.g. "xterm-256color")
ReadEnv-->>ReadEnv.output: Close
ReadEnv-->>BlockB: Disconnect
§Examples
§Using the block in a system
System::build(|s| {
let name_param = s.const_string("TERM");
let env_reader = s.read_env();
let line_encoder = s.encode_lines();
let stdout = s.write_stdout();
s.connect(&name_param.output, &env_reader.name);
s.connect(&env_reader.output, &line_encoder.input);
s.connect(&line_encoder.output, &stdout.input);
});§Running the block via the CLI
$ protoflow execute ReadEnv name=TERMFields§
§name: InputPort<String>The name of the environment variable to read.
output: OutputPort<T>The output message stream.
Implementations§
Trait Implementations§
Source§impl<T: Message + FromStr> Block for ReadEnv<T>
impl<T: Message + FromStr> Block for ReadEnv<T>
Source§fn execute(&mut self, runtime: &dyn BlockRuntime) -> BlockResult
fn execute(&mut self, runtime: &dyn BlockRuntime) -> BlockResult
Executes this block’s computation.
Source§fn prepare(&mut self, _runtime: &dyn BlockRuntime) -> Result<(), BlockError>
fn prepare(&mut self, _runtime: &dyn BlockRuntime) -> Result<(), BlockError>
Prepares this block for execution. Read more
Source§impl<T: Message + FromStr> BlockDescriptor for ReadEnv<T>
impl<T: Message + FromStr> BlockDescriptor for ReadEnv<T>
Source§fn inputs(&self) -> Vec<PortDescriptor>
fn inputs(&self) -> Vec<PortDescriptor>
A description of this block’s input ports.
Source§fn outputs(&self) -> Vec<PortDescriptor>
fn outputs(&self) -> Vec<PortDescriptor>
A description of this block’s output ports.
Source§fn parameters(&self) -> Vec<ParameterDescriptor>
fn parameters(&self) -> Vec<ParameterDescriptor>
A description of this block’s parameters.
Source§fn ports(&self) -> Vec<PortDescriptor>
fn ports(&self) -> Vec<PortDescriptor>
A description of this block’s I/O ports.
Source§impl<T: Message + FromStr> StdioSystem for ReadEnv<T>
impl<T: Message + FromStr> StdioSystem for ReadEnv<T>
fn build_system(config: StdioConfig) -> Result<System, StdioError>
Auto Trait Implementations§
impl<T> Freeze for ReadEnv<T>
impl<T = String> !RefUnwindSafe for ReadEnv<T>
impl<T> Send for ReadEnv<T>
impl<T> Sync for ReadEnv<T>
impl<T> Unpin for ReadEnv<T>where
T: Unpin,
impl<T = String> !UnwindSafe for ReadEnv<T>
Blanket Implementations§
Source§impl<T> AsBlockDescriptor for Twhere
T: BlockDescriptor,
impl<T> AsBlockDescriptor for Twhere
T: BlockDescriptor,
fn as_block_descriptor(&self) -> &dyn BlockDescriptor
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more