Struct protoflow_blocks::Const
source · pub struct Const<T: Message = String> {
pub output: OutputPort<T>,
pub value: T,
}Expand description
A block for sending a constant value.
This block sends a constant value on its output port. It can also be used to send a constant value to multiple blocks.
The value to send is specified as a parameter, and can be of any
type that implements the Message trait.
The block waits for the output port to be connected before sending the value, and closes the port after the value is sent.
The block does not have any input ports nor state.
§Block Diagram
block-beta
columns 4
Const space:2 Sink
Const-- "output" -->Sink
classDef block height:48px,padding:8px;
classDef hidden visibility:none;
class Const block
class Sink hidden
§Sequence Diagram
sequenceDiagram
autonumber
participant Const as Const block
participant Const.output as Const.output port
participant BlockA as Another block
Const-->>BlockA: Connect
Const->>BlockA: Message
Const-->>Const.output: Close
Const-->>BlockA: Disconnect
§Examples
§Using the block in a system
System::build(|s| {
let const_value = s.const_string("Hello, world!");
let line_encoder = s.encode_lines();
let stdout = s.write_stdout();
s.connect(&const_value.output, &line_encoder.input);
s.connect(&line_encoder.output, &stdout.input);
});§Running the block via the CLI
$ protoflow execute Const value=Hello
Fields§
§output: OutputPort<T>The port to send the value on.
value: TA parameter for the value to send.
Implementations§
source§impl<T: Message> Const<T>
impl<T: Message> Const<T>
pub fn with_params(output: OutputPort<T>, value: T) -> Self
Trait Implementations§
source§impl<T: Message> Block for Const<T>
impl<T: Message> Block for Const<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> BlockDescriptor for Const<T>
impl<T: Message> BlockDescriptor for Const<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§impl<T: Message> Definition for Const<T>
impl<T: Message> Definition for Const<T>
fn is_variation(&self) -> bool
source§impl<T: Message> Element for Const<T>
impl<T: Message> Element for Const<T>
source§fn short_name(&self) -> Option<&str>
fn short_name(&self) -> Option<&str>
The short name of the element, if any.
source§fn is_library_element(&self) -> bool
fn is_library_element(&self) -> bool
Whether this
Element is contained in the ownership tree of
a library model.source§fn owning_namespace(&self) -> Option<&dyn Namespace>
fn owning_namespace(&self) -> Option<&dyn Namespace>
source§fn owning_relationship(&self) -> Option<&dyn Relationship>
fn owning_relationship(&self) -> Option<&dyn Relationship>
fn qualified_name(&self) -> Option<QualifiedName>
source§impl<T: Message> OccurrenceDefinition for Const<T>
impl<T: Message> OccurrenceDefinition for Const<T>
fn is_individual(&self) -> bool
source§impl<T: Message> StdioSystem for Const<T>
impl<T: Message> StdioSystem for Const<T>
fn build_system(config: StdioConfig) -> Result<System, StdioError>
source§impl<T: Message> Type for Const<T>
impl<T: Message> Type for Const<T>
fn is_abstract(&self) -> bool
fn is_sufficient(&self) -> bool
fn is_conjugated(&self) -> bool
fn specializes(&self, _supertype: &Self) -> bool
impl<T: Message> BlockDefinition for Const<T>
impl<T: Message> Class for Const<T>
impl<T: Message> Classifier for Const<T>
impl<T: Message> ItemDefinition for Const<T>
impl<T: Message> PartDefinition for Const<T>
impl<T: Message> Structure for Const<T>
Auto Trait Implementations§
impl<T> Freeze for Const<T>where
T: Freeze,
impl<T = String> !RefUnwindSafe for Const<T>
impl<T> Send for Const<T>
impl<T> Sync for Const<T>
impl<T> Unpin for Const<T>where
T: Unpin,
impl<T = String> !UnwindSafe for Const<T>
Blanket Implementations§
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit)