1
Fork 0

Rollup merge of #117694 - jmillikin:core-io-borrowed-buf, r=m-ou-se

Move `BorrowedBuf` and `BorrowedCursor` from `std:io` to `core::io`

Tracking issue: https://github.com/rust-lang/rust/issues/117693

ACP: https://github.com/rust-lang/libs-team/issues/290
This commit is contained in:
Takayuki Maeda 2023-11-09 11:36:52 +09:00 committed by GitHub
commit b4fa5b7004
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 31 additions and 22 deletions

View file

@ -24,6 +24,7 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![feature(array_windows)] #![feature(array_windows)]
#![feature(cfg_match)] #![feature(cfg_match)]
#![feature(core_io_borrowed_buf)]
#![feature(if_let_guard)] #![feature(if_let_guard)]
#![feature(let_chains)] #![feature(let_chains)]
#![feature(min_specialization)] #![feature(min_specialization)]

View file

@ -1,10 +1,6 @@
#![unstable(feature = "read_buf", issue = "78485")] #![unstable(feature = "core_io_borrowed_buf", issue = "117693")]
#[cfg(test)]
mod tests;
use crate::fmt::{self, Debug, Formatter}; use crate::fmt::{self, Debug, Formatter};
use crate::io::{Result, Write};
use crate::mem::{self, MaybeUninit}; use crate::mem::{self, MaybeUninit};
use crate::{cmp, ptr}; use crate::{cmp, ptr};
@ -303,16 +299,3 @@ impl<'a> BorrowedCursor<'a> {
self.buf.filled += buf.len(); self.buf.filled += buf.len();
} }
} }
impl<'a> Write for BorrowedCursor<'a> {
fn write(&mut self, buf: &[u8]) -> Result<usize> {
let amt = cmp::min(buf.len(), self.capacity());
self.append(&buf[..amt]);
Ok(amt)
}
#[inline]
fn flush(&mut self) -> Result<()> {
Ok(())
}
}

View file

@ -0,0 +1,6 @@
//! Traits, helpers, and type definitions for core I/O functionality.
mod borrowed_buf;
#[unstable(feature = "core_io_borrowed_buf", issue = "117693")]
pub use self::borrowed_buf::{BorrowedBuf, BorrowedCursor};

View file

@ -369,6 +369,8 @@ pub mod async_iter;
pub mod cell; pub mod cell;
pub mod char; pub mod char;
pub mod ffi; pub mod ffi;
#[unstable(feature = "core_io_borrowed_buf", issue = "117693")]
pub mod io;
pub mod iter; pub mod iter;
pub mod net; pub mod net;
pub mod option; pub mod option;

View file

@ -1,5 +1,5 @@
use super::BorrowedBuf; use core::io::BorrowedBuf;
use crate::mem::MaybeUninit; use core::mem::MaybeUninit;
/// Test that BorrowedBuf has the correct numbers when created with new /// Test that BorrowedBuf has the correct numbers when created with new
#[test] #[test]

View file

@ -0,0 +1 @@
mod borrowed_buf;

View file

@ -23,6 +23,7 @@
#![feature(const_likely)] #![feature(const_likely)]
#![feature(const_location_fields)] #![feature(const_location_fields)]
#![feature(core_intrinsics)] #![feature(core_intrinsics)]
#![feature(core_io_borrowed_buf)]
#![feature(core_private_bignum)] #![feature(core_private_bignum)]
#![feature(core_private_diy_float)] #![feature(core_private_diy_float)]
#![feature(dec2flt)] #![feature(dec2flt)]
@ -135,6 +136,7 @@ mod fmt;
mod future; mod future;
mod hash; mod hash;
mod intrinsics; mod intrinsics;
mod io;
mod iter; mod iter;
mod lazy; mod lazy;
#[cfg(test)] #[cfg(test)]

View file

@ -528,3 +528,17 @@ impl<A: Allocator> Write for VecDeque<u8, A> {
Ok(()) Ok(())
} }
} }
#[unstable(feature = "read_buf", issue = "78485")]
impl<'a> io::Write for core::io::BorrowedCursor<'a> {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
let amt = cmp::min(buf.len(), self.capacity());
self.append(&buf[..amt]);
Ok(amt)
}
#[inline]
fn flush(&mut self) -> io::Result<()> {
Ok(())
}
}

View file

@ -330,7 +330,7 @@ pub use self::{
}; };
#[unstable(feature = "read_buf", issue = "78485")] #[unstable(feature = "read_buf", issue = "78485")]
pub use self::readbuf::{BorrowedBuf, BorrowedCursor}; pub use core::io::{BorrowedBuf, BorrowedCursor};
pub(crate) use error::const_io_error; pub(crate) use error::const_io_error;
mod buffered; mod buffered;
@ -339,7 +339,6 @@ mod cursor;
mod error; mod error;
mod impls; mod impls;
pub mod prelude; pub mod prelude;
mod readbuf;
mod stdio; mod stdio;
mod util; mod util;

View file

@ -310,6 +310,7 @@
// tidy-alphabetical-start // tidy-alphabetical-start
#![feature(char_internals)] #![feature(char_internals)]
#![feature(core_intrinsics)] #![feature(core_intrinsics)]
#![feature(core_io_borrowed_buf)]
#![feature(duration_constants)] #![feature(duration_constants)]
#![feature(error_generic_member_access)] #![feature(error_generic_member_access)]
#![feature(error_in_core)] #![feature(error_in_core)]