arxiv/arxiv.rs
1use crate::Arxiv;
2
3use anyhow::Result;
4
5use std::fs;
6use std::io::Write;
7
8impl Arxiv {
9 pub fn new() -> Self {
10 Arxiv::default()
11 }
12
13 /// Save the paper as a pdf from the information stored by the structure.
14 pub async fn fetch_pdf(&self, out_path: &str) -> Result<()> {
15 let body = reqwest::get(&self.pdf_url).await?.bytes().await?;
16 let out_path = if out_path.ends_with(".pdf") {
17 out_path.to_string()
18 } else {
19 format!("{}.pdf", out_path)
20 };
21 let mut file = fs::File::create(out_path)?;
22 file.write_all(&body)?;
23 Ok(())
24 }
25}