Skip to content

Commit 423ef0b

Browse files
committed
Get rid of static_assertions dependency
1 parent 0a2489c commit 423ef0b

File tree

5 files changed

+20
-14
lines changed

5 files changed

+20
-14
lines changed

spdlog/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ log = { version = "0.4.8", optional = true }
5050
once_cell = "1.16.0"
5151
spdlog-macros = { version = "0.1.0", path = "../spdlog-macros" }
5252
spin = "0.9.8"
53-
static_assertions = "1.1.0"
5453
thiserror = "1.0.37"
5554

5655
[target.'cfg(windows)'.dependencies]

spdlog/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ use std::{
66
};
77

88
use atomic::Atomic;
9-
use static_assertions::const_assert;
109
use thiserror::Error;
1110

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

spdlog/src/level.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub enum Level {
7272

7373
cfg_if! {
7474
if #[cfg(test)] {
75-
static_assertions::const_assert!(atomic::Atomic::<Level>::is_lock_free());
75+
crate::utils::const_assert!(atomic::Atomic::<Level>::is_lock_free());
7676
}
7777
}
7878

@@ -224,15 +224,12 @@ pub enum LevelFilter {
224224

225225
cfg_if! {
226226
if #[cfg(test)] {
227-
static_assertions::const_assert!(atomic::Atomic::<LevelFilter>::is_lock_free());
228-
static_assertions::const_assert_eq!(
229-
std::mem::size_of::<Level>() * 2,
230-
std::mem::size_of::<LevelFilter>()
231-
);
232-
static_assertions::const_assert_eq!(
233-
std::mem::align_of::<Level>() * 2,
234-
std::mem::align_of::<LevelFilter>()
235-
);
227+
use std::mem::{align_of, size_of};
228+
use crate::utils::const_assert;
229+
230+
const_assert!(atomic::Atomic::<LevelFilter>::is_lock_free());
231+
const_assert!(size_of::<Level>() * 2 == size_of::<LevelFilter>());
232+
const_assert!(align_of::<Level>() * 2 == align_of::<LevelFilter>());
236233
}
237234
}
238235

spdlog/src/sink/helper.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ pub(crate) type SinkErrorHandler = Atomic<Option<ErrorHandler>>;
1111

1212
cfg_if! {
1313
if #[cfg(test)] {
14-
use static_assertions::const_assert;
15-
const_assert!(Atomic::<SinkErrorHandler>::is_lock_free());
14+
crate::utils::const_assert!(Atomic::<SinkErrorHandler>::is_lock_free());
1615
}
1716
}
1817

spdlog/src/utils.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,14 @@ pub fn open_file(path: impl AsRef<Path>, truncate: bool) -> Result<File> {
2525
.open(path)
2626
.map_err(Error::OpenFile)
2727
}
28+
29+
// Credits `static_assertions` crate
30+
macro_rules! const_assert {
31+
( $cond:expr $(,)? ) => {
32+
const _: [(); 0 - !{
33+
const EVALUATED: bool = $cond;
34+
EVALUATED
35+
} as usize] = [];
36+
};
37+
}
38+
pub(crate) use const_assert;

0 commit comments

Comments
 (0)