
RsXiv
A Rust library to provide an interface for arXiv identifiers and the arXiv API.
Key features:
This crate will not make the network request itself.
For that, you might use ureq or reqwest.
Example
Example using ureq:
use std::{borrow::Cow, collections::BTreeMap};
use rsxiv::{
ArticleId, Query, Response,
query::{Combine, Field, FieldGroup, SortBy, SortOrder},
response::AuthorName,
};
use serde::Deserialize;
use ureq;
#[derive(Deserialize)]
struct Entry<'r> {
authors: Vec<AuthorName>,
title: Cow<'r, str>,
}
fn main() -> anyhow::Result<()> {
let mut query = Query::new();
query
.sort(SortBy::SubmittedDate, SortOrder::Ascending)
.search_query()
.init(Field::ti("Proton").unwrap())
.and(FieldGroup::init(Field::au("Bob").unwrap()).or(Field::au("John").unwrap()));
let response_body = ureq::get(query.url().as_ref())
.call()?
.into_body()
.read_to_vec()?;
let response = Response::<BTreeMap<ArticleId, Entry>>::from_xml(&response_body)?;
for (id, entry) in response.entries.iter() {
println!(
"'{}' by {}{} [{id}]",
entry.title,
entry.authors[0],
if entry.authors.len() > 1 {
" et al."
} else {
""
}
);
}
Ok(())
}