Module aho_corasick::util::int
source · Expand description
This module provides several integer oriented traits for converting between
both fixed size integers and integers whose size varies based on the target
(like usize
).
The main design principle for this module is to centralize all uses of as
.
The thinking here is that as
makes it very easy to perform accidental lossy
conversions, and if we centralize all its uses here under more descriptive
higher level operations, its use and correctness becomes easier to audit.
This was copied mostly wholesale from regex-automata
.
NOTE: for simplicity, we don’t take target pointer width into account here for
usize
conversions. Since we currently only panic in debug mode, skipping the
check when it can be proven it isn’t needed at compile time doesn’t really
matter. Now, if we wind up wanting to do as many checks as possible in release
mode, then we would want to skip those when we know the conversions are always
non-lossy.