Program Rust
parse_digits_into_seq
This Rust is the input prepared for Aeneas. Modeling choices explains the adaptations from the production source.
254 // Equivalent to `ByteSlice::parse_digits(|digit| d.try_add_digit(digit))`.255 // An explicit index keeps the closure's mutable borrow out of the enclosing256 // parser context while retaining the same wrapping digit test and updates.257 fn parse_digits_into_seq<'a>(s: &'a [u8], d: &mut DecimalSeq) -> &'a [u8] {258 let mut count = 0;259 while count < s.len() && s[count].wrapping_sub(b'0') < 10 {260 let digit = s[count].wrapping_sub(b'0');261 d.try_add_digit(digit);262 count += 1;263 }264 &s[count..]265 }266 267 /// Combine counts in i64 and clamp before casting to i32.268 #[inline]Aeneas 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 | 257:0–265:1 |
| Program version | Revised program |