#fizzbuzz #fizz #buzz

extended_fizzbuzz

Configurable FizzBuzz library

1 stable release

1.0.0 Sep 11, 2020

#3 in #fizz

MIT license

13KB
185 lines

extended_fizzbuzz Build

Configurable FizzBuzz library.

Installation

[dependencies]
extended_fizzbuzz = "1"

Usage

use extended_fizzbuzz::{fizzbuzz, Matcher};

fn main() {
    let matchers = vec![
        Matcher::new(3, "Fizz").expect("Failed to create `3=Fizz` matcher"),
        Matcher::new(5, "Buzz").expect("Failed to create `5=Buzz` matcher"),
    ];

    fizzbuzz(1, 100, &matchers).expect("FizzBuzzing failed");
}

License

See the license file for details.

Authors

Built with


lib.rs:

This library provides a configurable FizzBuzz implementation.

Examples

FizzBuzz from 1 to 15

use extended_fizzbuzz::{fizzbuzz, Matcher};

let matchers = vec![
    Matcher::new(3, "Fizz").unwrap(),
    Matcher::new(5, "Buzz").unwrap(),
];

fizzbuzz(1, 15, &matchers).unwrap();

Output:

1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz

FizzBuzz for single numbers

use extended_fizzbuzz::{line, Matcher};

let matchers = vec![
    Matcher::new(3, "Fizz").unwrap(),
    Matcher::new(5, "Buzz").unwrap(),
];

assert_eq!(line(6, &matchers), "Fizz".to_string());
assert_eq!(line(7, &matchers), "7".to_string());
assert_eq!(line(10, &matchers), "Buzz".to_string());
assert_eq!(line(15, &matchers), "FizzBuzz".to_string());

Dependencies

~320–770KB
~18K SLoC