rust_releases_io/client.rs
1use crate::document::RetrievedDocument;
2
3pub mod cached_client;
4pub mod errors;
5pub mod fs_client;
6pub mod remote_client;
7
8/// Fetch a document, given a `resource` description.
9pub trait RustReleasesClient {
10 /// The type of error returned by the client implementation.
11 type Error;
12
13 /// Fetch the document described by the `resource` file.
14 fn fetch(&self, resource: ResourceFile) -> Result<RetrievedDocument, Self::Error>;
15}
16
17/// A resource which can be fetched, named and stored.
18#[derive(Clone, Debug)]
19pub struct ResourceFile<'url, 'name> {
20 // Where the remote resource is located.
21 url: &'url str,
22 /// What the resource is to be named.
23 name: &'name str,
24}
25
26impl<'url, 'name> ResourceFile<'url, 'name> {
27 /// Create a new resource file.
28 ///
29 /// The `url` should point to the file to be fetched.
30 /// The `name` should refer to name of this resource. It is recommended that
31 /// each separate resource has a unique name.
32 pub fn new(url: &'url str, name: &'name str) -> Self {
33 Self { url, name }
34 }
35
36 /// The `url` points to the file to be fetched.
37 pub fn url(&self) -> &'url str {
38 self.url
39 }
40
41 /// The `name` is the identifier of this resource and is recommended to
42 /// be unique per resource.
43 pub fn name(&self) -> &'name str {
44 self.name
45 }
46}