From d108df86b4f4cf482556b1ca86f84a1c0a004b44 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Wed, 22 Jan 2025 13:13:04 -0800 Subject: [PATCH] tokens: add token serialization for AlgoTimeline Signed-off-by: William Casarin --- crates/notedeck_columns/src/timeline/kind.rs | 26 ++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/crates/notedeck_columns/src/timeline/kind.rs b/crates/notedeck_columns/src/timeline/kind.rs index 3b22129d..5e39135e 100644 --- a/crates/notedeck_columns/src/timeline/kind.rs +++ b/crates/notedeck_columns/src/timeline/kind.rs @@ -160,6 +160,32 @@ pub enum AlgoTimeline { LastPerPubkey(ListKind), } +/// The identifier for our last per pubkey algo +const LAST_PER_PUBKEY_TOKEN: &str = "last_per_pubkey"; + +impl TokenSerializable for AlgoTimeline { + fn serialize_tokens(&self, writer: &mut TokenWriter) { + match self { + AlgoTimeline::LastPerPubkey(list_kind) => { + writer.write_token(LAST_PER_PUBKEY_TOKEN); + list_kind.serialize_tokens(writer); + } + } + } + + fn parse_from_tokens<'a>(parser: &mut TokenParser<'a>) -> Result> { + TokenParser::alt( + parser, + &[|p| { + p.parse_all(|p| { + p.parse_token(LAST_PER_PUBKEY_TOKEN)?; + Ok(AlgoTimeline::LastPerPubkey(ListKind::parse_from_tokens(p)?)) + }) + }], + ) + } +} + impl Display for TimelineKind { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self {