Skip to main content

release_hub/source/
mod.rs

1//! Release-source abstraction and built-in source implementations.
2//!
3//! Most applications can rely on [`EndpointSource`] or [`GitHubSource`], while
4//! advanced integrations can implement [`ReleaseSource`] to fetch release data
5//! from any service that can produce a [`crate::RemoteRelease`].
6
7/// Endpoint-backed release source implementation.
8pub mod endpoint;
9/// GitHub Release-backed source implementation.
10pub mod github;
11
12use crate::RemoteRelease;
13use std::{future::Future, pin::Pin};
14
15/// Parameters supplied to a release source when resolving update metadata.
16#[derive(Debug, Clone)]
17pub struct SourceRequest {
18    /// Requested platform target such as `linux-x86_64`.
19    pub target: String,
20}
21
22impl SourceRequest {
23    /// Creates a new source request for the given canonical target string.
24    pub fn new(target: impl Into<String>) -> Self {
25        Self {
26            target: target.into(),
27        }
28    }
29}
30
31/// Boxed future returned by [`ReleaseSource::fetch`].
32///
33/// The boxed future keeps [`ReleaseSource`] object-safe, so callers can store
34/// sources behind trait objects such as `Box<dyn ReleaseSource>`.
35pub type SourceFuture<'a> = Pin<Box<dyn Future<Output = crate::Result<RemoteRelease>> + Send + 'a>>;
36
37/// Pluggable source of release metadata for the updater pipeline.
38///
39/// Implement this trait when update metadata comes from a service other than
40/// the built-in manifest endpoint or GitHub Release adapters.
41pub trait ReleaseSource: Send + Sync {
42    /// Fetches release metadata for the requested target.
43    fn fetch<'a>(&'a self, request: &'a SourceRequest) -> SourceFuture<'a>;
44}
45
46pub use endpoint::EndpointSource;
47pub use github::GitHubSource;