Skip to content

Commit b3e38ac

Browse files
committed
Move io::IoSlice[Mut] to alloc
1 parent f2ada0a commit b3e38ac

File tree

9 files changed

+379
-366
lines changed

9 files changed

+379
-366
lines changed
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
#[cfg(target_os = "hermit")]
2-
use hermit_abi::iovec;
3-
#[cfg(any(target_family = "unix", target_os = "trusty", target_os = "wasi"))]
4-
use libc::iovec;
1+
use core::ffi::c_void;
2+
use core::marker::PhantomData;
3+
use core::slice;
54

6-
use crate::ffi::c_void;
7-
use crate::marker::PhantomData;
8-
use crate::slice;
9-
#[cfg(target_os = "solid_asp3")]
10-
use crate::sys::pal::abi::sockets::iovec;
5+
#[derive(Copy, Clone)]
6+
#[repr(C)]
7+
struct iovec {
8+
iov_base: *mut c_void,
9+
iov_len: usize,
10+
}
1111

1212
#[derive(Copy, Clone)]
1313
#[repr(transparent)]
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//! Target-dependant definition of `IoSlice` and `IoSliceMut`
2+
//!
3+
//! This is necessary to do it in `alloc` because other parts of the crate need
4+
//! them even though they must have different layouts depending on the platform.
5+
//!
6+
//! However, we take great care to not leak platform-specific details and to not
7+
//! link to any library here.
8+
9+
#![allow(unreachable_pub)]
10+
11+
cfg_select! {
12+
any(target_family = "unix", target_os = "hermit", target_os = "solid_asp3", target_os = "trusty", target_os = "wasi") => {
13+
mod iovec;
14+
pub use iovec::*;
15+
}
16+
target_os = "windows" => {
17+
mod windows;
18+
pub use windows::*;
19+
}
20+
target_os = "uefi" => {
21+
mod uefi;
22+
pub use uefi::*;
23+
}
24+
_ => {
25+
mod unsupported;
26+
pub use unsupported::*;
27+
}
28+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! A buffer type used with `Write::write_vectored` for UEFI Networking APIs. Vectored writing to
22
//! File is not supported as of UEFI Spec 2.11.
33
4-
use crate::marker::PhantomData;
5-
use crate::slice;
4+
use core::marker::PhantomData;
5+
use core::slice;
66

77
#[derive(Copy, Clone)]
88
#[repr(C)]

library/std/src/sys/io/io_slice/unsupported.rs renamed to library/alloc/src/io/io_slice/unsupported.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use crate::mem;
2-
31
#[derive(Copy, Clone)]
42
pub struct IoSlice<'a>(&'a [u8]);
53

@@ -30,7 +28,7 @@ impl<'a> IoSliceMut<'a> {
3028

3129
#[inline]
3230
pub fn advance(&mut self, n: usize) {
33-
let slice = mem::take(&mut self.0);
31+
let slice = core::mem::take(&mut self.0);
3432
let (_, remaining) = slice.split_at_mut(n);
3533
self.0 = remaining;
3634
}

library/std/src/sys/io/io_slice/windows.rs renamed to library/alloc/src/io/io_slice/windows.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
use crate::marker::PhantomData;
2-
use crate::slice;
3-
use crate::sys::c;
1+
use core::marker::PhantomData;
2+
use core::slice;
3+
4+
#[derive(Copy, Clone)]
5+
#[repr(C)]
6+
pub struct WSABUF {
7+
pub len: u32,
8+
pub buf: *mut u8,
9+
}
410

511
#[derive(Copy, Clone)]
612
#[repr(transparent)]
713
pub struct IoSlice<'a> {
8-
vec: c::WSABUF,
14+
vec: WSABUF,
915
_p: PhantomData<&'a [u8]>,
1016
}
1117

@@ -14,7 +20,7 @@ impl<'a> IoSlice<'a> {
1420
pub fn new(buf: &'a [u8]) -> IoSlice<'a> {
1521
assert!(buf.len() <= u32::MAX as usize);
1622
IoSlice {
17-
vec: c::WSABUF { len: buf.len() as u32, buf: buf.as_ptr() as *mut u8 },
23+
vec: WSABUF { len: buf.len() as u32, buf: buf.as_ptr() as *mut u8 },
1824
_p: PhantomData,
1925
}
2026
}
@@ -39,18 +45,15 @@ impl<'a> IoSlice<'a> {
3945

4046
#[repr(transparent)]
4147
pub struct IoSliceMut<'a> {
42-
vec: c::WSABUF,
48+
vec: WSABUF,
4349
_p: PhantomData<&'a mut [u8]>,
4450
}
4551

4652
impl<'a> IoSliceMut<'a> {
4753
#[inline]
4854
pub fn new(buf: &'a mut [u8]) -> IoSliceMut<'a> {
4955
assert!(buf.len() <= u32::MAX as usize);
50-
IoSliceMut {
51-
vec: c::WSABUF { len: buf.len() as u32, buf: buf.as_mut_ptr() },
52-
_p: PhantomData,
53-
}
56+
IoSliceMut { vec: WSABUF { len: buf.len() as u32, buf: buf.as_mut_ptr() }, _p: PhantomData }
5457
}
5558

5659
#[inline]

0 commit comments

Comments
 (0)