pubmed_client/europe_pmc/
references.rs

1//! Europe PMC `references` endpoint operations (page-number pagination).
2
3use tracing::instrument;
4
5use pubmed_parser::europe_pmc::{
6    EuropePmcReference, EuropePmcReferenceList, parse_references_response,
7};
8
9use crate::error::Result;
10
11use super::client::EuropePmcClient;
12use super::id::EuropePmcId;
13use super::paged::PagedList;
14
15/// Path segment of the `references` list endpoint.
16const SEGMENT: &str = "references";
17
18impl PagedList for EuropePmcReferenceList {
19    type Item = EuropePmcReference;
20
21    fn hit_count(&self) -> u64 {
22        self.hit_count
23    }
24
25    fn into_items(self) -> Vec<Self::Item> {
26        self.references
27    }
28}
29
30impl EuropePmcClient {
31    /// Fetch a single page of the reference list (works cited) for a record.
32    #[instrument(skip(self), fields(id = %id, page, page_size))]
33    pub async fn get_references_page(
34        &self,
35        id: &EuropePmcId,
36        page: u32,
37        page_size: u32,
38    ) -> Result<EuropePmcReferenceList> {
39        self.get_list_page(id, SEGMENT, page, page_size, parse_references_response)
40            .await
41    }
42
43    /// Fetch all references for a record, following page numbers until exhausted.
44    #[instrument(skip(self), fields(id = %id))]
45    pub async fn get_references(&self, id: &EuropePmcId) -> Result<Vec<EuropePmcReference>> {
46        self.collect_list_pages(id, SEGMENT, parse_references_response)
47            .await
48    }
49}