chiark / gitweb /
Generalise SingletonSource to hold a whole vector.
authorSimon Tatham <anakin@pobox.com>
Thu, 4 Jan 2024 07:42:16 +0000 (07:42 +0000)
committerSimon Tatham <anakin@pobox.com>
Thu, 4 Jan 2024 08:16:16 +0000 (08:16 +0000)
The previous new() constructor is now a singleton(), so it can still
work for its current purpose.

src/file.rs

index 3a778596316c825180db99949435ee06ad3424d5..907b3f453004a8f6cfc6be76ae731f3e8c6dbfa2 100644 (file)
@@ -64,17 +64,18 @@ impl FileDataSource for FeedSource {
     fn extendable(&self) -> bool { true }
 }
 
-struct SingletonSource {
-    id: String,
+struct StaticSource {
+    ids: Vec<String>,
 }
 
-impl SingletonSource {
-    fn new(id: String) -> Self { SingletonSource { id } }
+impl StaticSource {
+    fn singleton(id: String) -> Self { StaticSource { ids: vec! { id } } }
+    fn vector(ids: Vec<String>) -> Self { StaticSource { ids } }
 }
 
-impl FileDataSource for SingletonSource {
+impl FileDataSource for StaticSource {
     fn get(&self, _client: &mut Client) -> (Vec<String>, 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<bool, ClientError> {
@@ -1054,7 +1055,7 @@ pub fn examine_user(client: &mut Client, account_id: &str) ->
         &format!("Information about user {username}"), 'H');
 
     let file = File::<ExamineUserFileType, _>::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::<DetailedStatusFileType, _>::new(
-        client, SingletonSource::new(st.id), title)?;
+        client, StaticSource::singleton(st.id), title)?;
     Ok(Box::new(file))
 }