diff --git a/Cargo.lock b/Cargo.lock index 593f780..39a0b0e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1368,6 +1368,7 @@ checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" name = "uring-common" version = "0.1.0" dependencies = [ + "bytes", "io-uring 0.6.0", "libc", ] diff --git a/tokio-epoll-uring/Cargo.toml b/tokio-epoll-uring/Cargo.toml index bb809e2..07e12a8 100644 --- a/tokio-epoll-uring/Cargo.toml +++ b/tokio-epoll-uring/Cargo.toml @@ -14,7 +14,7 @@ thiserror = "1.0.44" tokio = "1.29.1" tokio-util = "0.7.8" tracing = "0.1.37" -uring-common = { path = "../uring-common" } +uring-common = { path = "../uring-common" , features = [ "bytes" ] } nix = "0.26.2" [dev-dependencies] diff --git a/uring-common/Cargo.toml b/uring-common/Cargo.toml index 8f41d16..6b9823b 100644 --- a/uring-common/Cargo.toml +++ b/uring-common/Cargo.toml @@ -7,6 +7,7 @@ license = "MIT" # the same as tokio-uring at the time we forked it [dependencies] libc = "0.2.80" +bytes = { version = "1.0", optional = true } [target.'cfg(target_os = "linux")'.dependencies] io-uring = "0.6.0" diff --git a/uring-common/src/ext/impl_from_any_iobuf_for_slice.rs b/uring-common/src/ext/impl_from_any_iobuf_for_slice.rs new file mode 100644 index 0000000..7a64ba8 --- /dev/null +++ b/uring-common/src/ext/impl_from_any_iobuf_for_slice.rs @@ -0,0 +1,8 @@ +use crate::buf::{IoBuf, Slice}; + +impl From for Slice { + fn from(value: B) -> Self { + let len = value.bytes_init(); + Slice::new(value, 0, len) + } +} diff --git a/uring-common/src/ext/impl_iobuf_for_array.rs b/uring-common/src/ext/impl_iobuf_for_array.rs new file mode 100644 index 0000000..5a2baaf --- /dev/null +++ b/uring-common/src/ext/impl_iobuf_for_array.rs @@ -0,0 +1,13 @@ +unsafe impl crate::buf::IoBuf for [u8; N] { + fn stable_ptr(&self) -> *const u8 { + self.as_ptr() + } + + fn bytes_init(&self) -> usize { + self.len() + } + + fn bytes_total(&self) -> usize { + self.len() + } +} diff --git a/uring-common/src/ext/mod.rs b/uring-common/src/ext/mod.rs new file mode 100644 index 0000000..35ad527 --- /dev/null +++ b/uring-common/src/ext/mod.rs @@ -0,0 +1,2 @@ +pub mod impl_from_any_iobuf_for_slice; +pub mod impl_iobuf_for_array; diff --git a/uring-common/src/lib.rs b/uring-common/src/lib.rs index 8153c52..4eb1fe3 100644 --- a/uring-common/src/lib.rs +++ b/uring-common/src/lib.rs @@ -7,3 +7,7 @@ pub mod io_fd; #[cfg(target_os = "linux")] pub use io_uring; +#[cfg(target_os = "linux")] +pub use libc; + +pub mod ext;