1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
//! # Response deserialization
//!
//! This module describes the deserialization interface managed by the wrapper struct
//! [`Response<T>`].
//!
//! Here, `T` is any container of type `map` or `seq` in the
//! [serde data model](https://serde.rs/data-model.html), which itself contains an [`Entry`](crate::response::Entry)-like `map` into which to deserialize each entry.
//!
//! Jump to:
//!
//! - [Data model](#data-model)
//! - [Examples](#examples)
//!
//! ## Data model
//! This is a detailed summary of the deserialization model supported by this crate, using the
//! terminology from the [serde data model](https://serde.rs/data-model.html).
//!
//! Each type is recursively documented, and the default value (that is, the variant provided by
//! `deserialize_any`) is the first value in the numeric list.
//!
//! ### `Response<T>`
//! There are three container options for `T`:
//! 1. `Seq<Entry>`: all of the fields (including the identifier) are passed to `Entry`.
//! 2. `Map<ArticleId, EntryNoId>`: the article identifier for the entry is used as the key and
//! the remaining fields are passed to `EntryNoId`.
//! 3. `Option<Entry>`: same as `Seq<Entry>`, but expects either `0` or `1` entries.
//!
//! ### `Entry`
//! An `Entry` is a `Map` with the following explicit keys and corresponding values:
//! - `id`: `ArticleId`
//! - `updated`: `DateTime`
//! - `published`: `DateTime`
//! - `title`: `Str`
//! - `summary`: `Str`
//! - `authors`: `Seq<Author>`,
//! - `doi`: `Option<Str>`,
//! - `comment`: `Option<Str>`,
//! - `journal_ref`: `Option<Str>`,
//! - `primary_category`: `Option<Str>`,
//! - `category`: `Seq<Str>`,
//!
//! ### `EntryNoId`
//! Identical to `Entry`, but without the `id` field.
//!
//! ### `ArticleId`
//! A representation of a arXiv identifier. Can be deserialized as:
//!
//! 1. `Str`: the identifier string, like `0212.1234v3`.
//! 2. `Bytes`: the identifier as bytes.
//! 3. `u64`: the portable `u64` format obtained from
//! [`ArticleId::serialize`](crate::id::ArticleId::serialize)
//!
//! Can be deserialized as an [`ArticleId`](crate::id::ArticleId).
//!
//! ### DateTime
//! A datetime in RFC 3339 format.
//!
//! 1. `Str`: the raw value, like `1996-12-19T16:39:57-08:00`
//!
//! Can be deserialized using [`DateTime<FixedOffset>`](`chrono::DateTime::parse_from_rfc3339`).
//!
//! ### `Author`
//! A representation of an arXiv author. Can be deserialized as:
//! 1. `AuthorMap`: a map containing the `name` and optional affiliation
//! 2. `Str`: the raw value, unparsed. Parse using the [`AuthorName`].
//!
//! Can be deserialized as an [`AuthorName`]
//!
//! ### `AuthorMap`
//! A representation of an arXiv author, also capturing affiliation data. Contains fields:
//! - `name`: `Str` (can be deserialized as an [`AuthorName`])
//! - `affiliation`: `Option<Str>`
//!
//! ### `Str`
//! Any serde string type, like `str` or `string` or `borrowed_str`. Whenever possible, this
//! borrows from the input data, but this is not always possible because of escape sequences.
//!
//! ## Examples
//! ### Basic usage example
//! A basic example is as follows.
//! ```
//! use std::collections::BTreeSet;
//!
//! use rsxiv::{response::{Entry, Response}, id::ArticleId};
//! use serde::Deserialize;
//!
//! // abridged arXiv response obtained by querying
//! // `export.arxiv.org/api/query?search_query=cat:math.CA AND ti:diffuse`
//! let xml = // br#"<feed xmlns...
//! # let xml = xml.as_bytes();
//!
//! // deserialize an entry, only keeping the title
//! #[derive(PartialEq, Eq, PartialOrd, Ord, Deserialize)]
//! struct EntryTitle {
//! title: String,
//! }
//!
//! let response = Response::<BTreeSet<EntryTitle>>::from_xml(&xml).unwrap();
//! assert_eq!(response.entries.len(), 10);
//! assert_eq!(
//! response.entries.first().unwrap().title,
//! "A Note on the Axisymmetric Diffusion equation"
//! );
//! ```
//! It is also possible to deserialize into a `map`, in which case the identifier is used as the
//! key. Since [`ArticleId`](crate::ArticleId) implements [`Deserialize`], we can use it directly
//! as the key type.
//! ```
//! use std::collections::BTreeMap;
//!
//! use rsxiv::{response::{Entry, Response, AuthorName}, id::ArticleId};
//! use serde::Deserialize;
//!
//! // abridged arXiv response
//! let xml = // br#"<feed xmlns...
//! # let xml = xml.as_bytes();
//!
//! // deserialize an entry, only keeping the author names
//! #[derive(PartialEq, Eq, PartialOrd, Ord, Deserialize)]
//! struct EntryTitle {
//! // can also be deserialized as a Vec<Author { name, affiliation }>
//! authors: Vec<AuthorName>,
//! }
//!
//! let response = Response::<BTreeMap<ArticleId, EntryTitle>>::from_xml(&xml).unwrap();
//! assert_eq!(response.entries.len(), 10);
//! assert_eq!(
//! response.entries.get(&ArticleId::parse("1810.03952v2").unwrap()).unwrap().authors[2].to_string(),
//! "John Harlim"
//! );
//! ```
use ;
use ResponseDeserializer;
use crate;