Skip to main content

GitHubSource

Struct GitHubSource 

Source
pub struct GitHubSource { /* private fields */ }
Expand description

A Source which lists and downloads releases from a GitHub repository’s releases API.

The asset to download is selected by matching a glob pattern against each release’s asset file names, so your project can name its release assets however it likes — there is no required naming scheme. The pattern is the second argument to new:

use std::env::consts::{ARCH, EXE_SUFFIX, OS};
use update_rs::GitHubSource;

let source = GitHubSource::new(
    "sierrasoftworks/git-tool",
    format!("git-tool-{OS}-{ARCH}{EXE_SUFFIX}"),
)
.with_release_tag_prefix("v");

The naming helpers build common patterns for you, e.g. naming::go (git-tool-linux-amd64) or naming::rust (git-tool-x86_64-unknown-linux-gnu).

The pattern must match the asset’s whole file name (it is anchored at both ends), so an exact name won’t accidentally select a .sha256 checksum or .sig sidecar. It supports * (any sequence) and ? (single character) wildcards; every other character matches literally. release_tag_prefix is stripped from each Git tag before it is parsed as a semantic version, and tags that don’t parse afterwards are ignored.

When GitHub reports a SHA-256 digest for an asset, the downloaded bytes are verified against it before the update proceeds, so a corrupted or tampered download is rejected.

Implementations§

Source§

impl GitHubSource

Source

pub fn new(repo: impl Into<String>, asset_pattern: impl Into<String>) -> Self

Create a source for the owner/name repo (e.g. "sierrasoftworks/git-tool"), selecting the asset to download with the glob asset_pattern (e.g. "git-tool-linux-amd64" or "*-linux-amd64").

See the naming module for helpers that build a pattern for the current platform.

Source

pub fn with_release_tag_prefix(self, prefix: &str) -> Self

Strip prefix from each release’s Git tag before parsing it as a semantic version (e.g. "v" for vX.Y.Z tags).

Source

pub fn with_github_endpoints(self, web: &str, api: &str) -> Self

Override the GitHub web (web) and API (api) endpoints. This is primarily useful for pointing the source at a GitHub Enterprise instance or a mock server in tests. Trailing slashes are trimmed.

Trait Implementations§

Source§

impl Debug for GitHubSource

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for GitHubSource

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Source for GitHubSource

Source§

fn get_releases<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<Release>, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

List the releases which are available from this source, each carrying the asset relevant to the running platform in Release::variant.
Source§

fn get_binary<'life0, 'life1, 'life2, 'life3, 'async_trait, W>( &'life0 self, release: &'life1 Release, variant: &'life2 ReleaseVariant, into: &'life3 mut W, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where W: 'async_trait + Write + Send, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Download the binary for a specific release variant, writing it to the provided sink.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more