fibonacci 0.1.1

A generic Fibonacci sequence generator
Documentation
  • Coverage
  • 100%
    3 out of 3 items documented2 out of 3 items with examples
  • Size
  • Source code size: 25.51 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.27 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • anna-is-cute

fibonacci

A Fibonacci generator written in Rust. It's generic for types that implement num::Zero, num::One, num::CheckedAdd, and Clone.

There is no stipulation that the type be num::Unsigned, but the generator will never generate a negative number.

The generator handles overflow by returning None, stopping the iterator. For example, Fibonacci<u64> will overflow after the ninety-second element, so the iterator will end after producing its ninety-second element.

The following all hold true:

assert_eq!(12, Fibonacci::<u8>::default().take(300).collect::<Vec<_>>().len());
assert_eq!(23, Fibonacci::<u16>::default().take(300).collect::<Vec<_>>().len());
assert_eq!(46, Fibonacci::<u32>::default().take(300).collect::<Vec<_>>().len());
assert_eq!(92, Fibonacci::<u64>::default().take(300).collect::<Vec<_>>().len());

Note that u128 will not work, as the num crate does not implement any traits for it.