#build-time #timestamp #build #string #time #compile

macro no-std build_timestamp

Simple proc-macro to generate a build timestamp string as a const

1 unstable release

Uses old Rust 2015

0.1.0 Sep 8, 2018

#50 in #build-time

Download history 297/week @ 2024-05-22 492/week @ 2024-05-29 570/week @ 2024-06-05 593/week @ 2024-06-12 575/week @ 2024-06-19 1407/week @ 2024-06-26 1390/week @ 2024-07-03 1275/week @ 2024-07-10 1585/week @ 2024-07-17 2589/week @ 2024-07-24 1898/week @ 2024-07-31 1514/week @ 2024-08-07 1980/week @ 2024-08-14 1764/week @ 2024-08-21 1629/week @ 2024-08-28 1345/week @ 2024-09-04

6,895 downloads per month

MIT/Apache

7KB

Build Timestamp String Generator

build_timestamp is a simple proc-macro for Rust to generate a const string with a build timestamp (in UTC), formatted with strftime syntax.

Note: using this crate makes your build non-deterministic!

Note: using this crate requires nightly Rust

Example

// Rust2018 macro import
use build_timestamp::build_time;

// generates a `const BUILD_TIME: &str`
build_time!("%A %Y-%m-%d / %H:%M:%S");

fn main() {
    println!("This is {}, built on: {}",
        env!("CARGO_PKG_NAME"), BUILD_TIME);
}

Running this example will print something that looks like:

This is my_crate, built on: Saturday 2018-09-08 / 11:35:43

TODO

Features that I'd like this crate to support in the future:

  • proper error handling (currently just uses unwrap() to panic)
  • ability to specify the name for the generated const
  • non-UTC timezones

If you would like to implement any of this, I welcome patches.

Dependencies

~3MB
~60K SLoC