Happy Programmers Day

Today is Programmers Day! To celebrate, I just tried my hand at a Rust program. Rust is a fairly new programming language that has been in development for five or so years and just had its 1.0 release earlier this year.

If we wanted to check if today was Programmers Day, we’d probably discover the familiar struct Tm in the time crate. Just as in C, it has tm_yday, which is just what we need. To use it, we could start a new project with Cargo.

$ cargo new programmers_day --bin

Now add

[dependencies]
time = "0.1"

to our Cargo.toml and the following in our src/main.rs

extern crate time;

fn main() {
    if time::now().tm_yday == 255 {
        println!("Happy Programmers Day!");
    } else {
        println!("Ho hum, just another day.");
    }
}

et voilà!

$ cargo run
   Compiling programmers_day v0.1.0 (file:///home/tim/rust/programmers_day)
     Running `target/debug/programmers_day`
Happy Programmers Day!
Advertisements
Happy Programmers Day

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s