Skip to main content

update_rs/source/
mod.rs

1use crate::{Error, Release, ReleaseVariant};
2use std::io::Write;
3
4pub mod github;
5
6pub use github::GitHubSource;
7
8/// A source of application releases which the [`UpdateManager`](crate::UpdateManager)
9/// can list and download binaries from.
10///
11/// The crate ships [`GitHubSource`] which fetches releases from a GitHub
12/// repository's releases API, but you can implement this trait yourself to pull
13/// updates from any other location (a custom HTTP endpoint, an S3 bucket, a
14/// local directory, ...).
15///
16/// A source is responsible for selecting the asset relevant to the running
17/// platform: each [`Release`] it returns from [`get_releases`](Source::get_releases)
18/// should carry, in [`Release::variant`], the asset that should be installed here
19/// (for [`GitHubSource`], the asset matching the configured glob pattern) or
20/// `None` if there is none. The manager downloads [`Release::get_variant`].
21///
22/// Implementations must be cheap to construct via [`Default`] (the manager uses
23/// it for its generic-parameter default) and must be `Send + Sync` so the
24/// manager can be used from async contexts.
25#[async_trait::async_trait]
26pub trait Source: Default + std::fmt::Debug + Send + Sync {
27    /// List the releases which are available from this source, each carrying the
28    /// asset relevant to the running platform in [`Release::variant`].
29    async fn get_releases(&self) -> Result<Vec<Release>, Error>;
30
31    /// Download the binary for a specific release variant, writing it to the
32    /// provided sink.
33    async fn get_binary<W: Write + Send>(
34        &self,
35        release: &Release,
36        variant: &ReleaseVariant,
37        into: &mut W,
38    ) -> Result<(), Error>;
39}