Skip to content

Commit

Permalink
Get rid of static_assertions dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
SpriteOvO committed Nov 24, 2023
1 parent 0a2489c commit 423ef0b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 deletions.
1 change: 0 additions & 1 deletion spdlog/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ log = { version = "0.4.8", optional = true }
once_cell = "1.16.0"
spdlog-macros = { version = "0.1.0", path = "../spdlog-macros" }
spin = "0.9.8"
static_assertions = "1.1.0"
thiserror = "1.0.37"

[target.'cfg(windows)'.dependencies]
Expand Down
2 changes: 1 addition & 1 deletion spdlog/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use std::{
};

use atomic::Atomic;
use static_assertions::const_assert;
use thiserror::Error;

pub use crate::env_level::EnvLevelError;
use crate::utils::const_assert;
#[cfg(feature = "multi-thread")]
use crate::{sink::Task, RecordOwned};

Expand Down
17 changes: 7 additions & 10 deletions spdlog/src/level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub enum Level {

cfg_if! {
if #[cfg(test)] {
static_assertions::const_assert!(atomic::Atomic::<Level>::is_lock_free());
crate::utils::const_assert!(atomic::Atomic::<Level>::is_lock_free());
}
}

Expand Down Expand Up @@ -224,15 +224,12 @@ pub enum LevelFilter {

cfg_if! {
if #[cfg(test)] {
static_assertions::const_assert!(atomic::Atomic::<LevelFilter>::is_lock_free());
static_assertions::const_assert_eq!(
std::mem::size_of::<Level>() * 2,
std::mem::size_of::<LevelFilter>()
);
static_assertions::const_assert_eq!(
std::mem::align_of::<Level>() * 2,
std::mem::align_of::<LevelFilter>()
);
use std::mem::{align_of, size_of};
use crate::utils::const_assert;

const_assert!(atomic::Atomic::<LevelFilter>::is_lock_free());
const_assert!(size_of::<Level>() * 2 == size_of::<LevelFilter>());
const_assert!(align_of::<Level>() * 2 == align_of::<LevelFilter>());
}
}

Expand Down
3 changes: 1 addition & 2 deletions spdlog/src/sink/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ pub(crate) type SinkErrorHandler = Atomic<Option<ErrorHandler>>;

cfg_if! {
if #[cfg(test)] {
use static_assertions::const_assert;
const_assert!(Atomic::<SinkErrorHandler>::is_lock_free());
crate::utils::const_assert!(Atomic::<SinkErrorHandler>::is_lock_free());
}
}

Expand Down
11 changes: 11 additions & 0 deletions spdlog/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,14 @@ pub fn open_file(path: impl AsRef<Path>, truncate: bool) -> Result<File> {
.open(path)
.map_err(Error::OpenFile)
}

// Credits `static_assertions` crate
macro_rules! const_assert {
( $cond:expr $(,)? ) => {
const _: [(); 0 - !{
const EVALUATED: bool = $cond;
EVALUATED
} as usize] = [];
};
}
pub(crate) use const_assert;

0 comments on commit 423ef0b

Please sign in to comment.