diff options
author | Fredrik Meringdal <fmeringdal@hotmail.com> | 2020-11-01 22:36:38 +0100 |
---|---|---|
committer | Fredrik Meringdal <fmeringdal@hotmail.com> | 2020-11-01 22:36:38 +0100 |
commit | 000c7c9900cbe93f5a72bbbef3ad4eaa3906b132 (patch) | |
tree | e74d1bfe48f446f75a00dac875988a71d47fb1b4 /src/utils.rs | |
parent | ed603b788b23535b086f2a7491627e018e8dce5d (diff) | |
download | rust_rrule-000c7c9900cbe93f5a72bbbef3ad4eaa3906b132.zip |
FromStr impl for RRule and RRuleSet + docs
Diffstat (limited to 'src/utils.rs')
-rw-r--r-- | src/utils.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/utils.rs b/src/utils.rs new file mode 100644 index 0000000..ef09d54 --- /dev/null +++ b/src/utils.rs @@ -0,0 +1,15 @@ +pub fn pymod(a: isize, b: isize) -> isize { + let r = a % b; + // If r and b differ in sign, add b to wrap the result to the correct sign. + if (r > 0 && b < 0) || (r < 0 && b > 0) { + return r + b; + } + r +} + +pub fn is_some_and_not_empty<T>(v: &Option<Vec<T>>) -> bool { + match v { + Some(v) => !v.is_empty(), + None => false, + } +} |