pubmed_client/europe_pmc/
citations.rs1use tracing::instrument;
4
5use pubmed_parser::europe_pmc::{
6 EuropePmcCitation, EuropePmcCitationList, parse_citations_response,
7};
8
9use crate::error::Result;
10
11use super::client::EuropePmcClient;
12use super::id::EuropePmcId;
13use super::paged::PagedList;
14
15const SEGMENT: &str = "citations";
17
18impl PagedList for EuropePmcCitationList {
19 type Item = EuropePmcCitation;
20
21 fn hit_count(&self) -> u64 {
22 self.hit_count
23 }
24
25 fn into_items(self) -> Vec<Self::Item> {
26 self.citations
27 }
28}
29
30impl EuropePmcClient {
31 #[instrument(skip(self), fields(id = %id, page, page_size))]
33 pub async fn get_citations_page(
34 &self,
35 id: &EuropePmcId,
36 page: u32,
37 page_size: u32,
38 ) -> Result<EuropePmcCitationList> {
39 self.get_list_page(id, SEGMENT, page, page_size, parse_citations_response)
40 .await
41 }
42
43 #[instrument(skip(self), fields(id = %id))]
45 pub async fn get_citations(&self, id: &EuropePmcId) -> Result<Vec<EuropePmcCitation>> {
46 self.collect_list_pages(id, SEGMENT, parse_citations_response)
47 .await
48 }
49}