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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
//! A Rust client library for the [Ensembl REST API](https://rest.ensembl.org/).
//!
//! This crate is a port of [`goensemblrest`](https://github.com/gawbul/goensemblrest),
//! itself a port of [`pyEnsemblRest`](https://github.com/gawbul/pyEnsemblRest), and
//! covers all 106 endpoints.
//!
//! # Quickstart
//!
//! ```no_run
//! use ensemblrest::types::LookupRecord;
//! use ensemblrest::Client;
//!
//! # fn main() -> ensemblrest::Result<()> {
//! let client = Client::new()?;
//! let braf: LookupRecord = client.get_lookup_by_id("ENSG00000157764", &[])?.json()?;
//! println!("{} is a {}", braf.display_name, braf.biotype);
//! # Ok(())
//! # }
//! ```
//!
//! # Decoding responses
//!
//! Every endpoint method returns a [`Response`]. Decode it with [`Response::json`]
//! for JSON, or [`Response::text`] for the formats Ensembl serves as text.
//!
//! ```no_run
//! use ensemblrest::options::content_type;
//! use ensemblrest::Client;
//!
//! # fn main() -> ensemblrest::Result<()> {
//! let client = Client::new()?;
//! let fasta = client
//! .get_sequence_by_id("ENSG00000157764", &[content_type("text/x-fasta")])?
//! .text()?;
//! # Ok(())
//! # }
//! ```
//!
//! `json` accepts any [`serde::Deserialize`] type, so endpoints without a model in
//! [`types`] still work via [`serde_json::Value`].
//!
//! # GA4GH query structs
//!
//! The GA4GH search endpoints take a body of optional filters, most of them the
//! same type as their neighbours. Each such endpoint therefore takes a named
//! `Ga4gh*Query` struct rather than a row of positional `Option`s, so a
//! transposed pair cannot compile into a silently wrong query. Fields left
//! `None` are omitted from the request body.
//!
//! ```no_run
//! use ensemblrest::{Client, Ga4ghReferencesQuery};
//!
//! # fn main() -> ensemblrest::Result<()> {
//! let client = Client::new()?;
//! let references = client.search_ga4gh_references(
//! &Ga4ghReferencesQuery {
//! reference_set_id: Some("GRCh38"),
//! accession: Some("GCA_000001405"),
//! page_size: Some(10),
//! ..Default::default()
//! },
//! &[],
//! )?;
//! # Ok(())
//! # }
//! ```
//!
//! # Configuration
//!
//! ```no_run
//! use ensemblrest::Client;
//! use std::time::Duration;
//!
//! # fn main() -> ensemblrest::Result<()> {
//! let client = Client::builder()
//! .timeout(Duration::from_secs(30))
//! .rate_limit(15, Duration::from_secs(1))
//! .max_attempts(5)
//! .user_agent("my-tool/1.0")
//! .build()?;
//! # Ok(())
//! # }
//! ```
//!
//! [`Client`] is cheap to clone and shares one rate limiter and connection pool
//! across clones, so a cloned client observes one global rate limit.
//!
//! # Errors
//!
//! ```no_run
//! use ensemblrest::{ApiErrorKind, Client};
//!
//! # fn main() -> ensemblrest::Result<()> {
//! let client = Client::new()?;
//! match client.get_lookup_by_id("NOT_A_REAL_ID", &[]) {
//! Ok(response) => println!("{}", response.status()),
//! Err(e) if e.is_not_found() => println!("no such identifier"),
//! Err(e) if e.api_kind() == Some(ApiErrorKind::RateLimit) => println!("rate limited"),
//! Err(e) => println!("failed: {e}"),
//! }
//! # Ok(())
//! # }
//! ```
// `Error` is ~136 bytes, dominated by ApiError's String, Vec<u8> and RateLimitInfo.
// Every fallible function in this crate accompanies a network round trip, so the
// cost of moving it is immaterial and boxing it would change a public API shape
// that callers pattern-match on.
use Duration;
/// The current version of this crate.
pub const VERSION: &str = env!;
/// The official Ensembl REST API endpoint.
pub const DEFAULT_BASE_URL: &str = "https://rest.ensembl.org";
/// The default MIME type used for requests and responses.
pub const DEFAULT_CONTENT_TYPE: &str = "application/json";
/// The default per-request timeout.
pub const DEFAULT_TIMEOUT: Duration = from_secs;
/// The default maximum number of attempts for a single call.
pub const DEFAULT_MAX_ATTEMPTS: u32 = 5;
/// The default number of requests permitted per rate-limit window.
pub const DEFAULT_REQS_PER_SEC: u32 = 15;
/// The default rate-limit sliding-window duration.
pub const DEFAULT_WALL_TIME: Duration = from_secs;
/// The default cap on a single response body, in bytes (100 MiB).
///
/// `ureq` defaults to 10 MiB, which several Ensembl endpoints exceed.
pub const DEFAULT_MAX_RESPONSE_BYTES: u64 = 100 * 1024 * 1024;
/// The crate's minimum supported Rust version, from `rust-version` in
/// `Cargo.toml`.
///
/// `None` when built by a toolchain that does not set
/// `CARGO_PKG_RUST_VERSION`, or when `Cargo.toml` declares no `rust-version`.
pub const MSRV: = option_env!;
/// Returns the default `User-Agent` header value.
///
/// The Rust version is taken from [`MSRV`] rather than hardcoded, so bumping
/// `rust-version` in `Cargo.toml` cannot leave a stale number on the wire. If
/// the toolchain does not supply one, the version is left out altogether
/// rather than guessed.
/// Re-export of the `serde_json` version this crate was built against.
///
/// Use this to guarantee your `serde_json::Value` types match the ones
/// produced by this crate.
pub use serde_json;
pub use RateLimitInfo;
pub use ;
pub
pub use Response;
pub use ;
pub use ;
pub
pub use ;