I've been working on Colorlessgithub.com/veecore/colorless-rs, an experimental rust toolkit to address the classic "function coloring" problem without code duplication or coroutine overhead.
Quick Taste
Here is a streaming key-value parser driven by callbacks (`ColoredFnMut`):
#[colorless(C)] fn parse_records<'a, S, D>(mut source: S, mut sink: D) -> Result<usize, ()> where S: ColoredFnMut<(), C, Output = Option<&'a str>>, D: ColoredFnMut<(&'a str, &'a str), C, Output = Result<(), ()>>, { let mut count = 0; pin_local!(source); pin_local!(sink); borrow_mut!(source, sink); #[colorless::loop_state(mut source, mut sink, pub mut count)\] while let Some(line) = reborrow!(source).call_mut(()).resolve { if let Some((k, v)) = line.split_once('=') { reborrow!(sink).call_mut((k.trim(), v.trim())).resolve?; count += 1; } } Ok(count) } // 1. Run synchronously with direct closures: let sync_count = parse_records(from_fn(|| lines.next()), from_fn(|(k, v)| ...)).sync\_()?; // 2. Run asynchronously with async closures awaiting real socket I/O: let async_count = parse_records(from_async_fn(async || socket.read().await), ...).async\_().await?; Looking for Feedback On:
- The Safety & Drop Model: Macro-transformed code currently uses a relaxed implicit destruction model (documented in our README and SAFETY.md). I would love eyes from folks experienced with unsafe pin carriers and drop-order semantics.
- API Ergonomics: How the
ColoredFnMutand.resolveAPIs feel to use compared to standard sync/async patterns. - Compiler Lowering: Insights on our ANF representation and loop-state annotations.
The repository includes runnable examples (crates/facade/examples/) and a full test suite.
Any critique, feedback, or suggestions before we publish our first alpha to crates.io would be greatly appreciated!
1 post - 1 participant