Expand description
§overf
Define the overflow behavior of mathematical operations within blocks of code. This library provides the macros checked!, overflowing!, saturating!, propagating! and default!, enabling you to easily manage overflow in nested contexts.
§Usage
use overf::{checked, overflowing, saturating, default};
checked! {
let result = 1usize + 1usize;
let sum = default! { 2usize + 2usize }; // Use default behavior
let difference = 5usize - 3usize;
// Nested blocks
saturating! {
let total = 100u8 - 200u8;
}
}
overflowing! {
let result = 1usize + usize::MAX;
}§Features
- Customizable Overflow Behavior: Choose between checked, overflowing, and saturating operations for any block of code.
- Nested Blocks: Define different overflow behaviors in nested blocks for more granular control.
- Reset Behavior: Use the
default!macro to reset the overflow behavior back to the default.
§Installation
Add overf to your Cargo.toml:
[dependencies]
overf = "0.1"Or run the following command:
cargo add overfMacros§
- checked
- Defines a block of code where all mathematical operations are performed using checked methods.
- default
- Resets the overflow behavior to the default behavior of Rust.
- overflowing
- Defines a block of code where all mathematical operations use overflowing methods.
- propagating
- Defines a block of code where all mathematical operations use checked methods.
If any operation results in an overflow, it will return
None, propagating the error using the?operator. - saturating
- Defines a block of code where all mathematical operations use saturating methods.
- wrapping
- Defines a block of code where all mathematical operations use wrapping methods.