cute_dsp/
common.rs

1//! Common definitions and helper functions used by the rest of the library
2
3#![allow(unused_imports)]
4
5#[cfg(feature = "std")]
6use std::f32::consts::PI;
7
8#[cfg(not(feature = "std"))]
9use core::f32::consts::PI;
10
11/// The version of the library
12pub const VERSION_MAJOR: u32 = 1;
13pub const VERSION_MINOR: u32 = 6;
14pub const VERSION_PATCH: u32 = 2;
15pub const VERSION_STRING: &str = "1.6.2";
16
17/// Check if the library version is compatible (semver).
18/// Major versions are not compatible with each other.
19/// Minor and patch versions are backwards-compatible.
20#[inline]
21pub const fn version_check(major: u32, minor: u32, patch: u32) -> bool {
22    major == VERSION_MAJOR
23        && (VERSION_MINOR > minor
24            || (VERSION_MINOR == minor && VERSION_PATCH >= patch))
25}
26
27/// Macro to check the library version is compatible (semver).
28#[macro_export]
29macro_rules! version_check {
30    ($major:expr, $minor:expr, $patch:expr) => {
31        const _: bool = $crate::common::version_check($major, $minor, $patch);
32    };
33}
34
35#[cfg(test)]
36mod tests {
37    use super::*;
38
39    #[test]
40    fn test_version_check() {
41        assert!(version_check(1, 6, 2));
42        assert!(version_check(1, 6, 1));
43        assert!(version_check(1, 5, 0));
44        assert!(!version_check(2, 0, 0));
45        assert!(!version_check(1, 7, 0));
46    }
47}