Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/protoflow-blocks/src/blocks/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pub mod core {
use super::{
prelude::{vec, Box, Cow, Named, Vec},
prelude::{vec, Box, Bytes, Cow, Named, Vec},
BlockConnections, BlockInstantiation, InputPortName, OutputPortName, System,
};
use crate::{
Expand All @@ -14,6 +14,8 @@ pub mod core {
pub trait CoreBlocks {
fn buffer<T: Message + Into<T> + 'static>(&mut self) -> Buffer<T>;

fn const_bytes<T: Into<Bytes>>(&mut self, value: T) -> Const<Bytes>;

fn const_string(&mut self, value: impl ToString) -> Const<String>;

fn count<T: Message + 'static>(&mut self) -> Count<T>;
Expand Down
23 changes: 22 additions & 1 deletion lib/protoflow-blocks/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#![allow(dead_code)]

use crate::{
prelude::{fmt, Arc, Box, FromStr, Rc, String, ToString},
prelude::{fmt, Arc, Box, Bytes, FromStr, Rc, String, ToString},
types::{DelayType, Encoding},
AllBlocks, Buffer, ConcatStrings, Const, CoreBlocks, Count, Decode, DecodeCsv, DecodeHex,
DecodeJson, Delay, Drop, Encode, EncodeCsv, EncodeHex, EncodeJson, FlowBlocks, HashBlocks,
Expand Down Expand Up @@ -133,6 +133,11 @@ impl CoreBlocks for System {
self.0.block(Buffer::<T>::with_system(self))
}

fn const_bytes<T: Into<Bytes>>(&mut self, value: T) -> Const<Bytes> {
self.0
.block(Const::<Bytes>::with_system(self, value.into()))
}

fn const_string(&mut self, value: impl ToString) -> Const<String> {
self.0
.block(Const::<String>::with_system(self, value.to_string()))
Expand Down Expand Up @@ -308,3 +313,19 @@ impl TextBlocks for System {
.block(SplitString::with_system(self, Some(delimiter.to_string())))
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn const_bytes_accepts_various_types() {
let _ = System::build(|s| {
let _ = s.const_bytes("Hello world");
let _ = s.const_bytes("Hello world".to_string());
let _ = s.const_bytes(&b"Hello world"[..]);
let _ = s.const_bytes(b"Hello world".to_vec());
let _ = s.const_bytes(Bytes::from("Hello world"));
});
}
}