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