Program Rust
parse_digits_into_seq
This Rust is the input prepared for Aeneas. Modeling choices explains the adaptations from the production source.
253 // Equivalent to `ByteSlice::parse_digits(|digit| d.try_add_digit(digit))`.254 // An explicit index keeps the closure's mutable borrow out of the enclosing255 // parser context while retaining the same wrapping digit test and updates.256 fn parse_digits_into_seq<'a>(s: &'a [u8], d: &mut DecimalSeq) -> &'a [u8] {257 let mut count = 0;258 while count < s.len() && s[count].wrapping_sub(b'0') < 10 {259 let digit = s[count].wrapping_sub(b'0');260 d.try_add_digit(digit);261 count += 1;262 }263 &s[count..]264 }265 266 // Equivalent to the source exponent `parse_digits` closure. Bytes after the267 // first nondigit were ignored by the caller, so only the accumulated value isAeneas declaration
The Lean below was mechanically extracted by Aeneas from Rust.
def num.imp.dec2flt.decimal_seq.parse_digits_into_seq
(s : Slice Std.U8) (d : num.imp.dec2flt.decimal_seq.DecimalSeq) :
Result ((Slice Std.U8) × num.imp.dec2flt.decimal_seq.DecimalSeq)
:= do
let (d1, count) ←
num.imp.dec2flt.decimal_seq.parse_digits_into_seq_loop s d 0#usize
let s1 ←
core.slice.index.Slice.index
(core.slice.index.SliceIndexRangeFromUsizeSlice Std.U8) s
{ start := count }
ok (s1, d1)Source details
| Declaration | num.imp.dec2flt.decimal_seq.parse_digits_into_seq |
|---|---|
| File | num/imp/../../dec2flt/decimal_seq.rs |
| Lines | 256:0–264:1 |
| Program version | Original program |