pub struct Count<T: Message> {
pub input: InputPort<T>,
pub output: OutputPort<T>,
pub count: OutputPort<u64>,
/* private fields */
}Expand description
A block that counts the number of messages it receives, while optionally passing them through.
§Block Diagram
block-beta
columns 7
Source space:2 Count space:2 Sink
space:7
space:7
space:3 Result space:3
Source-- "input" -->Count
Count-- "output" -->Sink
Count-- "count" -->Result
classDef block height:48px,padding:8px;
classDef hidden visibility:none;
class Count block
class Source hidden
class Sink hidden
class Result hidden
§Sequence Diagram
sequenceDiagram
autonumber
participant BlockA as Another block
participant Count.input as Count.input port
participant Count as Count block
participant Count.output as Count.output port
participant BlockB as Another block
participant Count.count as Count.count port
participant BlockC as Another block
BlockA-->>Count: Connect
Count-->>BlockB: Connect
loop Count process
BlockA->>Count: Message
Count->>Count: Increment counter
Count->>BlockB: Message
end
BlockA-->>Count: Disconnect
Count-->>Count.input: Close
Count-->>Count.output: Close
Count-->>BlockB: Disconnect
Count-->>BlockC: Connect
Count->>BlockC: Counter
Count-->>Count.count: Close
Count-->>BlockC: Disconnect
%% TODO
§Examples
§Using the block in a system
System::build(|s| {
let stdin = s.read_stdin();
let line_decoder = s.decode_lines();
let counter = s.count::<String>();
let count_encoder = s.encode_lines();
let stdout = s.write_stdout();
s.connect(&stdin.output, &line_decoder.input);
s.connect(&line_decoder.output, &counter.input);
s.connect(&counter.count, &count_encoder.input);
s.connect(&count_encoder.output, &stdout.input);
});§Running the block via the CLI
$ protoflow execute CountFields§
§input: InputPort<T>The input message stream.
output: OutputPort<T>The (optional) output target for the stream being passed through.
count: OutputPort<u64>The output port for the message count.
Implementations§
source§impl<T: Message> Count<T>
impl<T: Message> Count<T>
pub fn new( input: InputPort<T>, output: OutputPort<T>, count: OutputPort<u64>, ) -> Self
Trait Implementations§
source§impl<T: Message> Block for Count<T>
impl<T: Message> Block for Count<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 Count<T>
impl<T: Message> BlockDescriptor for Count<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§impl<T: Message> Definition for Count<T>
impl<T: Message> Definition for Count<T>
fn is_variation(&self) -> bool
source§impl<T: Message> Element for Count<T>
impl<T: Message> Element for Count<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> MaybeLabeled for Count<T>
impl<T: Message> MaybeLabeled for Count<T>
source§impl<T: Message> MaybeNamed for Count<T>
impl<T: Message> MaybeNamed for Count<T>
source§impl<T: Message> OccurrenceDefinition for Count<T>
impl<T: Message> OccurrenceDefinition for Count<T>
fn is_individual(&self) -> bool
source§impl<T: Message + FromStr + ToString + 'static> StdioSystem for Count<T>
impl<T: Message + FromStr + ToString + 'static> StdioSystem for Count<T>
fn build_system(config: StdioConfig) -> Result<System, StdioError>
source§impl<T: Message> Type for Count<T>
impl<T: Message> Type for Count<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 Count<T>
impl<T: Message> Class for Count<T>
impl<T: Message> Classifier for Count<T>
impl<T: Message> ItemDefinition for Count<T>
impl<T: Message> PartDefinition for Count<T>
impl<T: Message> Structure for Count<T>
Auto Trait Implementations§
impl<T> Freeze for Count<T>
impl<T> !RefUnwindSafe for Count<T>
impl<T> Send for Count<T>
impl<T> Sync for Count<T>
impl<T> Unpin for Count<T>where
T: Unpin,
impl<T> !UnwindSafe for Count<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)