diff options
| author | ihc童鞋@提不起劲 <[email protected]> | 2023-01-13 16:56:53 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-01-13 16:56:53 +0800 |
| commit | 26f0fa4c76e63648af274b6d1536a626c4640211 (patch) | |
| tree | b1b09a9d061ece99525ece56bc54e65a8c09b48e | |
| parent | 1546e29c75b1a4b0f8b1c5d39f8b3b332143575d (diff) | |
refactor: use auto-const-array to declare const array with cfg feature (#130)
* refactor: use auto-const-array to declare const array with cfg feature
* fix clippy issues
| -rw-r--r-- | monoio/Cargo.toml | 1 | ||||
| -rw-r--r-- | monoio/src/buf/io_vec_buf.rs | 2 | ||||
| -rw-r--r-- | monoio/src/utils/uring_detect.rs | 63 |
3 files changed, 24 insertions, 42 deletions
diff --git a/monoio/Cargo.toml b/monoio/Cargo.toml index dd25ea8..a129241 100644 --- a/monoio/Cargo.toml +++ b/monoio/Cargo.toml @@ -14,6 +14,7 @@ version = "0.0.9" [dependencies] monoio-macros = {version = "0.0.3", path = "../monoio-macros", optional = true} +auto-const-array = "0.2" fxhash = "0.2" libc = "0.2" pin-project-lite = "0.2" diff --git a/monoio/src/buf/io_vec_buf.rs b/monoio/src/buf/io_vec_buf.rs index 8e3deea..061c602 100644 --- a/monoio/src/buf/io_vec_buf.rs +++ b/monoio/src/buf/io_vec_buf.rs @@ -4,6 +4,7 @@ /// /// # Safety /// See the safety note of the methods. +#[allow(clippy::unnecessary_safety_doc)] pub unsafe trait IoVecBuf: Unpin + 'static { /// Returns a raw pointer to iovec struct. /// struct iovec { @@ -145,6 +146,7 @@ impl From<VecBuf> for Vec<Vec<u8>> { /// /// # Safety /// See the safety note of the methods. +#[allow(clippy::unnecessary_safety_doc)] pub unsafe trait IoVecBufMut: Unpin + 'static { #[cfg(unix)] /// Returns a raw mutable pointer to iovec struct. diff --git a/monoio/src/utils/uring_detect.rs b/monoio/src/utils/uring_detect.rs index f8ca53d..5df97bb 100644 --- a/monoio/src/utils/uring_detect.rs +++ b/monoio/src/utils/uring_detect.rs @@ -1,13 +1,6 @@ //! Detect if current platform support io_uring. #[cfg(all(target_os = "linux", feature = "iouring"))] -macro_rules! op_codes { - ($($op: ident),*) => { - [$(io_uring::opcode::$op::CODE),*] - }; -} - -#[cfg(all(target_os = "linux", feature = "iouring"))] macro_rules! err_to_false { ($e: expr) => { match $e { @@ -27,42 +20,28 @@ fn detect_uring_inner() -> bool { } _ => {} } - #[cfg(not(feature = "splice"))] - const USED_OP: [u8; 14] = op_codes![ - Accept, - AsyncCancel, - Close, - Connect, - Fsync, - OpenAt, - ProvideBuffers, - Read, - Readv, - Recv, - Send, - Timeout, - Write, - Writev - ]; - #[cfg(feature = "splice")] - const USED_OP: [u8; 15] = op_codes![ - Accept, - AsyncCancel, - Close, - Connect, - Fsync, - OpenAt, - ProvideBuffers, - Read, - Readv, - Recv, - Send, - Timeout, - Write, - Writev, - Splice - ]; + use io_uring::opcode::*; + auto_const_array::auto_const_array! { + const USED_OP: [u8; _] = [ + Accept::CODE, + AsyncCancel::CODE, + Close::CODE, + Connect::CODE, + Fsync::CODE, + OpenAt::CODE, + ProvideBuffers::CODE, + Read::CODE, + Readv::CODE, + Recv::CODE, + Send::CODE, + Timeout::CODE, + Write::CODE, + Writev::CODE, + #[cfg(feature = "splice")] + Splice::CODE + ]; + } let uring = err_to_false!(io_uring::IoUring::new(2)); let mut probe = io_uring::Probe::new(); |
