copybook-overflow
Overflow-safe integer narrowing and bounds arithmetic for copybook-rs.
Overview
This microcrate isolates checked arithmetic and checked narrowing conversions that are
performance-sensitive and correctness-critical. All functions return structured
copybook_error::Result<T> with domain-specific error codes on overflow, ensuring
COBOL array bounds and record sizes are computed safely.
Usage
use ;
// Safely compute array end offset: base + (count * item_size)
let end = safe_array_bound.unwrap;
assert_eq!;
// Safely narrow u64 to u32
let narrow = safe_u64_to_u32.unwrap;
assert_eq!;
Public API
safe_array_bound— Overflow-checkedbase + count * item_sizesafe_u64_to_u32— Checked narrowing fromu64tou32safe_u64_to_u16— Checked narrowing fromu64tou16safe_usize_to_u32— Checked narrowing fromusizetou32
License
AGPL-3.0-or-later