pub struct PmcTarClient { /* private fields */ }Expand description
TAR extraction client for PMC Open Access articles
Implementations§
Source§impl PmcTarClient
impl PmcTarClient
Sourcepub fn new(config: ClientConfig) -> Self
pub fn new(config: ClientConfig) -> Self
Create a new PMC TAR client with configuration
Sourcepub async fn download_and_extract_tar<P: AsRef<Path>>(
&self,
pmcid: &str,
output_dir: P,
) -> Result<Vec<String>>
pub async fn download_and_extract_tar<P: AsRef<Path>>( &self, pmcid: &str, output_dir: P, ) -> Result<Vec<String>>
Download and extract tar.gz file for a PMC article using the OA API
§Arguments
pmcid- PMC ID (with or without “PMC” prefix)output_dir- Directory to extract the tar.gz contents to
§Returns
Returns a Result<Vec<String>> containing the list of extracted file paths
§Errors
ParseError::InvalidPmid- If the PMCID format is invalidPubMedError::RequestError- If the HTTP request failsParseError::IoError- If file operations failParseError::PmcNotAvailable- If the article is not available in OA
§Example
use pubmed_client::pmc::tar::PmcTarClient;
use pubmed_client::ClientConfig;
use std::path::Path;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = ClientConfig::new();
let client = PmcTarClient::new(config);
let output_dir = Path::new("./extracted_articles");
let files = client.download_and_extract_tar("PMC7906746", output_dir).await?;
for file in files {
println!("Extracted: {}", file);
}
Ok(())
}Sourcepub async fn extract_figures_with_captions<P: AsRef<Path>>(
&self,
pmcid: &str,
output_dir: P,
) -> Result<Vec<ExtractedFigure>>
pub async fn extract_figures_with_captions<P: AsRef<Path>>( &self, pmcid: &str, output_dir: P, ) -> Result<Vec<ExtractedFigure>>
Download, extract tar.gz file, and match figures with their captions from XML
§Arguments
pmcid- PMC ID (with or without “PMC” prefix)output_dir- Directory to extract the tar.gz contents to
§Returns
Returns a Result<Vec<ExtractedFigure>> containing figures with both XML metadata and file paths
§Errors
ParseError::InvalidPmid- If the PMCID format is invalidPubMedError::RequestError- If the HTTP request failsParseError::IoError- If file operations failParseError::PmcNotAvailable- If the article is not available in OA
§Example
use pubmed_client::pmc::tar::PmcTarClient;
use pubmed_client::ClientConfig;
use std::path::Path;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = ClientConfig::new();
let client = PmcTarClient::new(config);
let output_dir = Path::new("./extracted_articles");
let figures = client.extract_figures_with_captions("PMC7906746", output_dir).await?;
for figure in figures {
println!("Figure {}: {}", figure.figure.id, figure.figure.caption);
println!("File: {}", figure.extracted_file_path);
}
Ok(())
}Trait Implementations§
Source§impl Clone for PmcTarClient
impl Clone for PmcTarClient
Source§fn clone(&self) -> PmcTarClient
fn clone(&self) -> PmcTarClient
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for PmcTarClient
impl !RefUnwindSafe for PmcTarClient
impl Send for PmcTarClient
impl Sync for PmcTarClient
impl Unpin for PmcTarClient
impl !UnwindSafe for PmcTarClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more