Skip to main content

alpaca_data/news/
response.rs

1use alpaca_core::{Error, pagination::PaginatedResponse};
2use serde::{Deserialize, Serialize};
3
4use super::NewsItem;
5
6#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
7pub struct ListResponse {
8    #[serde(default)]
9    pub news: Vec<NewsItem>,
10    pub next_page_token: Option<String>,
11}
12
13impl PaginatedResponse for ListResponse {
14    fn next_page_token(&self) -> Option<&str> {
15        self.next_page_token.as_deref()
16    }
17
18    fn merge_page(&mut self, mut next: Self) -> Result<(), Error> {
19        self.news.append(&mut next.news);
20        self.next_page_token = next.next_page_token;
21        Ok(())
22    }
23
24    fn clear_next_page_token(&mut self) {
25        self.next_page_token = None;
26    }
27}