Skip to content
Learning basic Rust via variations on the FizzBuzz game.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.gitignore
Cargo.lock
Cargo.toml
README.md
fizz_buzz-closure.rs
fizz_buzz-devel.rs
fizz_buzz-if-let.rs
fizz_buzz-looper.rs
fizz_buzz-match.rs

README.md

My Public GitHub Page Is Here My Website Is Here

Fizz Buzz Variations in Rust

Exploring the FizzBuzz Game as an exercise in learning the Rust Language I came up with four solutions exhibited here along with a development version containing some initial exploration.

If you haven't tried solving the FizzBuzz Game before, you might want to try solving it in your favorite language and perhaps also explore Rust a bit before looking at these SPOILERS.

In reverse chronological order these are:

File Technique
fizz_buzz-closure.rs heap-allocated closures
fizz_buzz-if-let.rs cyclic iterators with if let
fizz_buzz-match.rs cyclic iterators with match
fizz_buzz-looper.rs mutable structures
fizz_buzz-devel.rs early exploration and false starts

My first idea was to use closures. I didn't know enough to make that work until I'd found the other solutions. I was delighted when I found the trick of creating cyclic iterators using standard components.

I would love to find a flexible approach that didn't require so much mutability without incurring the usual overhead of using the mod operator or growing the heap. Tail Call Optimization would help but Rust doesn't offer that yet.

J. Greg Davidson, Thursday, 30 April 2015

You can’t perform that action at this time.