Skip to content
Closed
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
8 changes: 8 additions & 0 deletions library/alloc/src/io/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,13 @@ impl<A> WriteThroughCursor for &mut Vec<u8, A>
where
A: Allocator,
{
#[inline]
fn write(this: &mut Cursor<Self>, buf: &[u8]) -> io::Result<usize> {
let (pos, inner) = this.into_parts_mut();
vec_write_all(pos, inner, buf)
}

#[inline]
fn write_vectored(this: &mut Cursor<Self>, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
let (pos, inner) = this.into_parts_mut();
vec_write_all_vectored(pos, inner, bufs)
Expand All @@ -163,12 +165,14 @@ where
true
}

#[inline]
fn write_all(this: &mut Cursor<Self>, buf: &[u8]) -> io::Result<()> {
let (pos, inner) = this.into_parts_mut();
vec_write_all(pos, inner, buf)?;
Ok(())
}

#[inline]
fn write_all_vectored(this: &mut Cursor<Self>, bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
let (pos, inner) = this.into_parts_mut();
vec_write_all_vectored(pos, inner, bufs)?;
Expand All @@ -186,11 +190,13 @@ impl<A> WriteThroughCursor for Vec<u8, A>
where
A: Allocator,
{
#[inline]
fn write(this: &mut Cursor<Self>, buf: &[u8]) -> io::Result<usize> {
let (pos, inner) = this.into_parts_mut();
vec_write_all(pos, inner, buf)
}

#[inline]
fn write_vectored(this: &mut Cursor<Self>, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
let (pos, inner) = this.into_parts_mut();
vec_write_all_vectored(pos, inner, bufs)
Expand All @@ -201,12 +207,14 @@ where
true
}

#[inline]
fn write_all(this: &mut Cursor<Self>, buf: &[u8]) -> io::Result<()> {
let (pos, inner) = this.into_parts_mut();
vec_write_all(pos, inner, buf)?;
Ok(())
}

#[inline]
fn write_all_vectored(this: &mut Cursor<Self>, bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
let (pos, inner) = this.into_parts_mut();
vec_write_all_vectored(pos, inner, bufs)?;
Expand Down
11 changes: 11 additions & 0 deletions library/core/src/io/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ impl<T> Cursor<T> {
/// # fn force_inference(_: &Cursor<Vec<u8>>) {}
/// # force_inference(&buff);
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_io_structs", since = "1.79.0")]
pub const fn new(inner: T) -> Cursor<T> {
Expand All @@ -115,6 +116,7 @@ impl<T> Cursor<T> {
///
/// let vec = buff.into_inner();
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn into_inner(self) -> T {
self.inner
Expand All @@ -133,6 +135,7 @@ impl<T> Cursor<T> {
///
/// let reference = buff.get_ref();
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_io_structs", since = "1.79.0")]
pub const fn get_ref(&self) -> &T {
Expand All @@ -155,6 +158,7 @@ impl<T> Cursor<T> {
///
/// let reference = buff.get_mut();
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_mut_cursor", since = "1.86.0")]
pub const fn get_mut(&mut self) -> &mut T {
Expand All @@ -180,6 +184,7 @@ impl<T> Cursor<T> {
/// buff.seek(SeekFrom::Current(-1)).unwrap();
/// assert_eq!(buff.position(), 1);
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_io_structs", since = "1.79.0")]
pub const fn position(&self) -> u64 {
Expand All @@ -203,6 +208,7 @@ impl<T> Cursor<T> {
/// buff.set_position(4);
/// assert_eq!(buff.position(), 4);
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_mut_cursor", since = "1.86.0")]
pub const fn set_position(&mut self, pos: u64) {
Expand Down Expand Up @@ -239,6 +245,7 @@ where
/// buff.set_position(6);
/// assert_eq!(buff.split(), ([1, 2, 3, 4, 5].as_slice(), [].as_slice()));
/// ```
#[inline]
#[unstable(feature = "cursor_split", issue = "86369")]
pub fn split(&self) -> (&[u8], &[u8]) {
let slice = self.inner.as_ref();
Expand Down Expand Up @@ -270,6 +277,7 @@ where
/// buff.set_position(6);
/// assert_eq!(buff.split_mut(), ([1, 2, 3, 4, 5].as_mut_slice(), [].as_mut_slice()));
/// ```
#[inline]
#[unstable(feature = "cursor_split", issue = "86369")]
pub fn split_mut(&mut self) -> (&mut [u8], &mut [u8]) {
let slice = self.inner.as_mut();
Expand Down Expand Up @@ -438,6 +446,7 @@ impl<T> io::Seek for Cursor<T>
where
T: AsRef<[u8]>,
{
#[inline]
fn seek(&mut self, style: SeekFrom) -> io::Result<u64> {
let (base_pos, offset) = match style {
SeekFrom::Start(n) => {
Expand All @@ -459,10 +468,12 @@ where
}
}

#[inline]
fn stream_len(&mut self) -> io::Result<u64> {
Ok(self.get_ref().as_ref().len() as u64)
}

#[inline]
fn stream_position(&mut self) -> io::Result<u64> {
Ok(self.position())
}
Expand Down
1 change: 1 addition & 0 deletions library/core/src/io/size_hint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub trait SizeHint {
/// `(self.lower_bound(), self.upper_bound())`.
///
/// Without specialization, types implementing this trait will return `(0, None)`.
#[inline]
final fn size_hint(&self) -> (usize, Option<usize>) {
(self.lower_bound(), self.upper_bound())
}
Expand Down
7 changes: 7 additions & 0 deletions library/core/src/io/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ pub trait Write {
/// ```
///
/// [`write`]: Write::write
#[inline]
#[stable(feature = "iovec", since = "1.36.0")]
fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize> {
default_write_vectored(|b| self.write(b), bufs)
Expand All @@ -146,6 +147,7 @@ pub trait Write {
/// The default implementation returns `false`.
///
/// [`write_vectored`]: Write::write_vectored
#[inline]
#[unstable(feature = "can_vector", issue = "69941")]
fn is_write_vectored(&self) -> bool {
false
Expand Down Expand Up @@ -210,6 +212,7 @@ pub trait Write {
/// Ok(())
/// }
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
fn write_all(&mut self, mut buf: &[u8]) -> Result<()> {
while !buf.is_empty() {
Expand Down Expand Up @@ -274,6 +277,7 @@ pub trait Write {
/// assert_eq!(writer, &[1, 2, 3, 4, 5, 6]);
/// # Ok(()) }
/// ```
#[inline]
#[unstable(feature = "write_all_vectored", issue = "70436")]
fn write_all_vectored(&mut self, mut bufs: &mut [IoSlice<'_>]) -> Result<()> {
// Guarantee that bufs is empty if it contains no data,
Expand Down Expand Up @@ -327,6 +331,7 @@ pub trait Write {
/// Ok(())
/// }
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
fn write_fmt(&mut self, args: fmt::Arguments<'_>) -> Result<()> {
if let Some(s) = args.as_statically_known_str() {
Expand Down Expand Up @@ -357,6 +362,7 @@ pub trait Write {
/// Ok(())
/// }
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
fn by_ref(&mut self) -> &mut Self
where
Expand All @@ -368,6 +374,7 @@ pub trait Write {

/// Default implementation of [`Write::write_vectored`], which is currently used
/// in `libstd` for file system implementations of similar methods.
#[inline]
#[doc(hidden)]
#[unstable(feature = "core_io_internals", reason = "exposed only for libstd", issue = "none")]
pub fn default_write_vectored<F>(write: F, bufs: &[IoSlice<'_>]) -> Result<usize>
Expand Down
Loading