Struct GitSHA1

Source
pub struct GitSHA1 { /* private fields */ }

Implementations§

Source§

impl GitSHA1

Source

pub fn use_default(self, default: &str) -> Self

Although designed with Git in mind, your crate may be compiled from source without being in a Git repository. This lets you define the value which is used instead of the real Git SHA1 as a drop-in replacement. The default value is “” (an empty string).

§Example
GitSHA1::read().use_default("<empty>").set("GIT_SHA1");
// will use: GIT_SHA1="<empty>"
Source

pub fn read() -> Self

Read current Git SHA1 by running git rev-parse HEAD.

This only retrieves the SHA1 from git. Use set(name) to pass compile-time environment variable to cargo-build. Afterwards it can be read from your source files.

If the current crate is not a git repository, the read will silently fail and the returned string in the end will be substituded by a default value.

Source

pub fn from_env(name: &str) -> Self

Read the comiple-time environment variable from carto-build. This can be used during runtime, i.e. in fn main() {}.

§Note:

You can read the Git SHA1 statically using env!:

// "GIT_SHA1" set in `build.rs`
const GIT_SHA1: &'static str = env!("GIT_SHA1");
Source

pub fn set(&self, name: &str)

Generate cargo environment variable for long Git SHA1.

§Example
GitSHA1::read().set("GIT_SHA1");
Source

pub fn long(&self) -> String

Return the complete SHA1 as a String.

Source

pub fn short(&self, count: usize) -> String

Return a subset of digits (short sha) as a String.

§Note

The number of digits extracted is silently truncated to the maximum number of digits available in the Git SHA1.

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, 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, 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.