pub struct GitSHA1 { /* private fields */ }
Implementations§
Source§impl GitSHA1
impl GitSHA1
Sourcepub fn use_default(self, default: &str) -> Self
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>"
Sourcepub fn read() -> Self
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.
Sourcepub fn from_env(name: &str) -> Self
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");