From 185ebac2ad32ccb98a96da3281c62d4763a81baf Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Thu, 4 Jan 2024 07:42:16 +0000 Subject: [PATCH] Generalise SingletonSource to hold a whole vector. The previous new() constructor is now a singleton(), so it can still work for its current purpose. --- src/file.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/file.rs b/src/file.rs index 3a77859..907b3f4 100644 --- a/src/file.rs +++ b/src/file.rs @@ -64,17 +64,18 @@ impl FileDataSource for FeedSource { fn extendable(&self) -> bool { true } } -struct SingletonSource { - id: String, +struct StaticSource { + ids: Vec, } -impl SingletonSource { - fn new(id: String) -> Self { SingletonSource { id } } +impl StaticSource { + fn singleton(id: String) -> Self { StaticSource { ids: vec! { id } } } + fn vector(ids: Vec) -> Self { StaticSource { ids } } } -impl FileDataSource for SingletonSource { +impl FileDataSource for StaticSource { fn get(&self, _client: &mut Client) -> (Vec, isize) { - (vec! { self.id.clone() }, 0) + (self.ids.clone(), 0) } fn init(&self, _client: &mut Client) -> Result<(), ClientError> { Ok(()) } fn try_extend(&self, _client: &mut Client) -> Result { @@ -1054,7 +1055,7 @@ pub fn examine_user(client: &mut Client, account_id: &str) -> &format!("Information about user {username}"), 'H'); let file = File::::new( - client, SingletonSource::new(ac.id), title)?; + client, StaticSource::singleton(ac.id), title)?; Ok(Box::new(file)) } @@ -1078,6 +1079,6 @@ pub fn view_single_post(client: &mut Client, status_id: &str) -> &format!("Information about post {}", st.id), 'H'); let file = File::::new( - client, SingletonSource::new(st.id), title)?; + client, StaticSource::singleton(st.id), title)?; Ok(Box::new(file)) } -- 2.30.2