Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions library/alloc/src/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ use core::{fmt, mem, ops, ptr, slice};

use crate::borrow::{Cow, ToOwned};
use crate::boxed::Box;
#[cfg(not(no_rc))]
use crate::rc::Rc;
use crate::string::String;
#[cfg(target_has_atomic = "ptr")]
#[cfg(all(not(no_rc), not(no_sync), target_has_atomic = "ptr"))]
use crate::sync::Arc;
use crate::vec::Vec;

Expand Down Expand Up @@ -898,7 +899,7 @@ impl<'a> From<&'a CString> for Cow<'a, CStr> {
}
}

#[cfg(target_has_atomic = "ptr")]
#[cfg(all(not(no_rc), not(no_sync), target_has_atomic = "ptr"))]
#[stable(feature = "shared_from_slice2", since = "1.24.0")]
impl From<CString> for Arc<CStr> {
/// Converts a [`CString`] into an <code>[Arc]<[CStr]></code> by moving the [`CString`]
Expand All @@ -910,7 +911,7 @@ impl From<CString> for Arc<CStr> {
}
}

#[cfg(target_has_atomic = "ptr")]
#[cfg(all(not(no_rc), not(no_sync), target_has_atomic = "ptr"))]
#[stable(feature = "shared_from_slice2", since = "1.24.0")]
impl From<&CStr> for Arc<CStr> {
/// Converts a `&CStr` into a `Arc<CStr>`,
Expand All @@ -922,7 +923,7 @@ impl From<&CStr> for Arc<CStr> {
}
}

#[cfg(target_has_atomic = "ptr")]
#[cfg(all(not(no_rc), not(no_sync), target_has_atomic = "ptr"))]
#[stable(feature = "shared_from_mut_slice", since = "1.84.0")]
impl From<&mut CStr> for Arc<CStr> {
/// Converts a `&mut CStr` into a `Arc<CStr>`,
Expand All @@ -933,6 +934,7 @@ impl From<&mut CStr> for Arc<CStr> {
}
}

#[cfg(not(no_rc))]
#[stable(feature = "shared_from_slice2", since = "1.24.0")]
impl From<CString> for Rc<CStr> {
/// Converts a [`CString`] into an <code>[Rc]<[CStr]></code> by moving the [`CString`]
Expand All @@ -944,6 +946,7 @@ impl From<CString> for Rc<CStr> {
}
}

#[cfg(not(no_rc))]
#[stable(feature = "shared_from_slice2", since = "1.24.0")]
impl From<&CStr> for Rc<CStr> {
/// Converts a `&CStr` into a `Rc<CStr>`,
Expand All @@ -955,6 +958,7 @@ impl From<&CStr> for Rc<CStr> {
}
}

#[cfg(not(no_rc))]
#[stable(feature = "shared_from_mut_slice", since = "1.84.0")]
impl From<&mut CStr> for Rc<CStr> {
/// Converts a `&mut CStr` into a `Rc<CStr>`,
Expand All @@ -965,6 +969,7 @@ impl From<&mut CStr> for Rc<CStr> {
}
}

#[cfg(not(no_rc))]
#[cfg(not(no_global_oom_handling))]
#[stable(feature = "more_rc_default_impls", since = "1.80.0")]
impl Default for Rc<CStr> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use crate::io::{
self, BorrowedCursor, BufRead, DEFAULT_BUF_SIZE, IoSliceMut, Read, Seek, SeekFrom, SizeHint,
SpecReadByte, uninlined_slow_read_byte,
};
use crate::string::String;
use crate::vec::Vec;

/// The `BufReader<R>` struct adds buffering to any reader.
///
Expand Down Expand Up @@ -74,11 +76,15 @@ impl<R: Read> BufReader<R> {
BufReader::with_capacity(DEFAULT_BUF_SIZE, inner)
}

pub(crate) fn try_new_buffer() -> io::Result<Buffer> {
#[unstable(feature = "io_internals", issue = "none")]
#[doc(hidden)]
pub fn try_new_buffer() -> io::Result<Buffer> {
Buffer::try_with_capacity(DEFAULT_BUF_SIZE)
}

pub(crate) fn with_buffer(inner: R, buf: Buffer) -> Self {
#[unstable(feature = "io_internals", issue = "none")]
#[doc(hidden)]
pub fn with_buffer(inner: R, buf: Buffer) -> Self {
Self { inner, buf }
}

Expand Down Expand Up @@ -285,9 +291,9 @@ impl<R: ?Sized> BufReader<R> {
}

// This is only used by a test which asserts that the initialization-tracking is correct.
#[cfg(test)]
impl<R: ?Sized> BufReader<R> {
#[allow(missing_docs)]
#[unstable(feature = "io_internals", issue = "none")]
#[doc(hidden)]
pub fn initialized(&self) -> usize {
self.buf.initialized()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
//! that user code which wants to do reads from a `BufReader` via `buffer` + `consume` can do so
//! without encountering any runtime bounds checks.

use crate::cmp;
use core::cmp;
use core::mem::MaybeUninit;

use crate::boxed::Box;
use crate::io::{self, BorrowedBuf, ErrorKind, Read};
use crate::mem::MaybeUninit;

#[derive(Debug)]
pub struct Buffer {
// The buffer.
buf: Box<[MaybeUninit<u8>]>,
Expand Down Expand Up @@ -69,7 +72,7 @@ impl Buffer {
}

// This is only used by a test which asserts that the initialization-tracking is correct.
#[cfg(test)]
#[inline]
pub fn initialized(&self) -> usize {
self.initialized
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use core::mem::{self, ManuallyDrop};
use core::{error, fmt, ptr};

use crate::io::{
self, DEFAULT_BUF_SIZE, ErrorKind, IntoInnerError, IoSlice, Seek, SeekFrom, Write,
};
use crate::mem::{self, ManuallyDrop};
use crate::{error, fmt, ptr};
use crate::vec::Vec;

/// Wraps a writer and buffers its output.
///
Expand Down Expand Up @@ -94,13 +96,17 @@ impl<W: Write> BufWriter<W> {
BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner)
}

pub(crate) fn try_new_buffer() -> io::Result<Vec<u8>> {
#[unstable(feature = "io_internals", issue = "none")]
#[doc(hidden)]
pub fn try_new_buffer() -> io::Result<Vec<u8>> {
Vec::try_with_capacity(DEFAULT_BUF_SIZE).map_err(|_| {
io::const_error!(ErrorKind::OutOfMemory, "failed to allocate write buffer")
})
}

pub(crate) fn with_buffer(inner: W, buf: Vec<u8>) -> Self {
#[unstable(feature = "io_internals", issue = "none")]
#[doc(hidden)]
pub fn with_buffer(inner: W, buf: Vec<u8>) -> Self {
Self { inner, buf, panicked: false }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ use crate::io::{self, BufWriter, IoSlice, Write};
/// `BufWriters` to be temporarily given line-buffering logic; this is what
/// enables Stdout to be alternately in line-buffered or block-buffered mode.
#[derive(Debug)]
pub struct LineWriterShim<'a, W: ?Sized + Write> {
pub(super) struct LineWriterShim<'a, W: ?Sized + Write> {
buffer: &'a mut BufWriter<W>,
}

impl<'a, W: ?Sized + Write> LineWriterShim<'a, W> {
pub fn new(buffer: &'a mut BufWriter<W>) -> Self {
pub(super) fn new(buffer: &'a mut BufWriter<W>) -> Self {
Self { buffer }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ mod linewritershim;
#[cfg(test)]
mod tests;

use core::{error, fmt};

#[stable(feature = "bufwriter_into_parts", since = "1.56.0")]
pub use bufwriter::WriterPanicked;
use linewritershim::LineWriterShim;

#[stable(feature = "rust1", since = "1.0.0")]
pub use self::{bufreader::BufReader, bufwriter::BufWriter, linewriter::LineWriter};
use crate::io::Error;
use crate::{error, fmt};

/// An error returned by [`BufWriter::into_inner`] which combines an error that
/// happened while writing out the buffer, and the buffered writer object
Expand Down
Loading
Loading