bcd 0.1.0

Binary coded decimal library
type Digit = u64;
use bcd::BigBcd;
use std::mem::swap;

pub struct BcdFibIter(BigBcd<Digit>, BigBcd<Digit>);

impl BcdFibIter {
    pub fn new() -> BcdFibIter {
        BcdFibIter(vec![0].into(), vec![1].into())
    }

    pub fn advance(&mut self) {
        self.0 += &self.1;
        swap(&mut self.0, &mut self.1);
    }

    pub fn get<'a>(&'a self) -> &'a BigBcd<Digit> {
        &self.1
    }
}

impl Iterator for BcdFibIter {
    type Item = BigBcd<Digit>;

    fn next(&mut self) -> Option<Self::Item> {
        self.advance();
        Some(self.get().clone())
    }
}