-
-
Save jamesmunns/1fa1de16be5ced030313e38859ca6dbf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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