Function fraction::division::divide_rem_resume

source ·
pub fn divide_rem_resume<I, Consumer>(
    state: DivisionState<I>,
    consumer: Consumer,
) -> Result<DivisionState<I>, DivisionError>
Expand description

divide_rem co-routine implementation
Performs the division, changes the state and returns it

§Examples

use fraction::division::{DivisionState, divide_rem_resume};

let mut state = Some(DivisionState::new(1, 3));
let mut precision = 5;

let mut result: Vec<u8> = Vec::new();

loop {
    if precision == 0 { break }

    state = Some(
        divide_rem_resume(state.take().unwrap(), |s, digit| {
            precision -= 1;
            result.push(digit);

            Ok(Err(s))
        }).unwrap()
    );

    // perform some other operations
}

assert_eq!(result, vec![3, 3, 3, 3, 3]);