Analyze code to suggest and add Design by Contract specifications (preconditions, postconditions, invariants, semantic invariants) in any language. Trigger on: "Design by Contract", "DBC", "preconditions", "postconditions", "class invariants", "code contracts", "formal specifications", "document assumptions", "add contracts", "make this function safer", "define what this function guarantees", "add assertions to document behavior", Bertrand Meyer, Eiffel contracts, or when discussing invariants that should always hold. Do NOT skip for non-Eiffel code — DBC applies everywhere via assertions, type guards, properties.
92
90%
Does it follow best practices?
Impact
95%
1.05xAverage score across 5 eval scenarios
Passed
No known issues
A Rust library exposes pagination helpers used by several API clients. Bugs have occurred when a page size of zero reached the helper and when offset arithmetic overflowed in large imports. Improve the contract expression so invalid pagination is caught early and valid callers get clear guarantees.
Produce pagination_contract_analysis.md, pagination.rs, and pagination_tests.rs.
=============== FILE: pagination.rs ===============
pub fn page_offset(page: usize, page_size: usize) -> usize {
(page - 1) * page_size
}
pub fn total_pages(total_items: usize, page_size: usize) -> usize {
(total_items + page_size - 1) / page_size
}