Function fraction::division::write_digit
source · pub fn write_digit(
writeable: &mut dyn Write,
digit: u8,
) -> Result<bool, DivisionError>
Expand description
A helper function to use in conjunction with divide_to_callback
divide_to_callback passes digits to its callback, this function can be used to write digits (and dots) into the writeable buffer after your callback performs its side-effects.
§Examples
use fraction::division::{divide_to_callback, write_digit};
let mut result = String::new();
let mut length = 0;
// calculate 7/4, which is 1.75
divide_to_callback(7, 4, 2, false, |d| { length += 1; write_digit(&mut result, d) }).ok();
assert_eq!(&result, "1.75");
assert_eq!(length, result.len());