Skip to content

Instantly share code, notes, and snippets.

@jamesmunns
Last active August 2, 2025 18:39
Show Gist options
  • Select an option

  • Save jamesmunns/1fa1de16be5ced030313e38859ca6dbf to your computer and use it in GitHub Desktop.

Select an option

Save jamesmunns/1fa1de16be5ced030313e38859ca6dbf to your computer and use it in GitHub Desktop.
topic!(ErgotFmtTxTopic, ErgotFmtTx<'a>, "ergot/.well-known/fmt");
topic!(ErgotFmtRxTopic, ErgotFmtRx<'a>, "ergot/.well-known/fmt");
#[derive(Serialize)]
pub struct ErgotFmtTx<'a> {
inner: core::fmt::Arguments<'a>,
}
#[derive(Serialize, Deserialize)]
pub struct ErgotFmtRx<'a> {
inner: &'a str,
}
impl<'a> Schema for ErgotFmtTx<'a> {
const SCHEMA: &'static NamedType = <&str as Schema>::SCHEMA;
}
impl<'a> Schema for ErgotFmtRx<'a> {
const SCHEMA: &'static NamedType = <&str as Schema>::SCHEMA;
}
#[cfg(test)]
mod test {
use super::*;
use crate::traits::Topic;
fn taker(x: &ErgotFmtTx<'_>) -> Vec<u8> {
postcard::to_stdvec(x).unwrap()
}
#[test]
fn fmt_punning_works() {
assert_eq!(ErgotFmtTxTopic::TOPIC_KEY, ErgotFmtRxTopic::TOPIC_KEY);
let x = 10;
let y = "world";
let res = taker(&ErgotFmtTx {
inner: format_args!("hello {x}, {}", y),
});
let res = postcard::from_bytes::<ErgotFmtRx<'_>>(&res).unwrap();
assert_eq!(res.inner, "hello 10, world");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment