Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the Wrapping type #5

Merged
merged 9 commits into from
Sep 15, 2022
Merged

Implement the Wrapping type #5

merged 9 commits into from
Sep 15, 2022

Conversation

pedromfedricci
Copy link
Owner

@pedromfedricci pedromfedricci commented Sep 13, 2022

Introduces the Wrapping type, analogous to core::num::Wrapping.

The Wrapping type provides intentionally-wrapped arithmetic on Constrained types that it holds. Currently implements: Add, AddAssign, Sub and SubAssign traits for all constrained integers. Implements signum, is_positive, is_negative for signed constrained integers.

The Wrapping type also implements serde's Serialize and Deserialize behind the serde feature flag, if the contained T implements them.

Usage example:

use constrained_int::i8::ConstrainedI8;
use constrained_int::wrapping::Wrapping;

type Value = Wrapping<ConstrainedI8<-20, 42>>;

let mut value = Value::default();
value += 10;
value -= -5;
value: Value = value + value;
assert_eq!(-1, value.signum());

@codecov-commenter
Copy link

codecov-commenter commented Sep 13, 2022

Codecov Report

Merging #5 (5b7376f) into main (39541d3) will increase coverage by 0.14%.
The diff coverage is 100.00%.

@@             Coverage Diff             @@
##             main        #5      +/-   ##
===========================================
+ Coverage   99.85%   100.00%   +0.14%     
===========================================
  Files           4         8       +4     
  Lines         689       787      +98     
===========================================
+ Hits          688       787      +99     
+ Misses          1         0       -1     
Impacted Files Coverage Δ
src/deserialize/macros.rs 100.00% <ø> (ø)
src/macros/common.rs 100.00% <ø> (ø)
src/macros/int.rs 100.00% <ø> (+0.33%) ⬆️
src/macros/uint.rs 100.00% <ø> (ø)
src/macros/refops.rs 100.00% <100.00%> (ø)
src/wrapping/macros/common.rs 100.00% <100.00%> (ø)
src/wrapping/macros/int.rs 100.00% <100.00%> (ø)
src/wrapping/mod.rs 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@pedromfedricci pedromfedricci marked this pull request as ready for review September 14, 2022 03:33
@pedromfedricci pedromfedricci merged commit 42fd3ec into main Sep 15, 2022
@pedromfedricci pedromfedricci deleted the wrapping_int_impl branch September 15, 2022 01:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants