Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8883bcf

Browse files
authoredMay 30, 2024
Rollup merge of rust-lang#125342 - tbu-:pr_doc_write, r=ChrisDenton
Document platform-specifics for `Read` and `Write` of `File`
2 parents e935223 + dd196e7 commit 8883bcf

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed
 

‎std/src/fs.rs

+76
Original file line numberDiff line numberDiff line change
@@ -767,11 +767,33 @@ fn buffer_capacity_required(mut file: &File) -> Option<usize> {
767767

768768
#[stable(feature = "rust1", since = "1.0.0")]
769769
impl Read for &File {
770+
/// Read some bytes from the file.
771+
///
772+
/// See [`Read::read`] docs for more info.
773+
///
774+
/// # Platform-specific behavior
775+
///
776+
/// This function currently corresponds to the `read` function on Unix and
777+
/// the `NtReadFile` function on Windows. Note that this [may change in
778+
/// the future][changes].
779+
///
780+
/// [changes]: io#platform-specific-behavior
770781
#[inline]
771782
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
772783
self.inner.read(buf)
773784
}
774785

786+
/// Like `read`, except that it reads into a slice of buffers.
787+
///
788+
/// See [`Read::read_vectored`] docs for more info.
789+
///
790+
/// # Platform-specific behavior
791+
///
792+
/// This function currently corresponds to the `readv` function on Unix and
793+
/// falls back to the `read` implementation on Windows. Note that this
794+
/// [may change in the future][changes].
795+
///
796+
/// [changes]: io#platform-specific-behavior
775797
#[inline]
776798
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
777799
self.inner.read_vectored(bufs)
@@ -782,6 +804,16 @@ impl Read for &File {
782804
self.inner.read_buf(cursor)
783805
}
784806

807+
/// Determines if `File` has an efficient `read_vectored` implementation.
808+
///
809+
/// See [`Read::is_read_vectored`] docs for more info.
810+
///
811+
/// # Platform-specific behavior
812+
///
813+
/// This function currently returns `true` on Unix an `false` on Windows.
814+
/// Note that this [may change in the future][changes].
815+
///
816+
/// [changes]: io#platform-specific-behavior
785817
#[inline]
786818
fn is_read_vectored(&self) -> bool {
787819
self.inner.is_read_vectored()
@@ -803,19 +835,63 @@ impl Read for &File {
803835
}
804836
#[stable(feature = "rust1", since = "1.0.0")]
805837
impl Write for &File {
838+
/// Write some bytes from the file.
839+
///
840+
/// See [`Write::write`] docs for more info.
841+
///
842+
/// # Platform-specific behavior
843+
///
844+
/// This function currently corresponds to the `write` function on Unix and
845+
/// the `NtWriteFile` function on Windows. Note that this [may change in
846+
/// the future][changes].
847+
///
848+
/// [changes]: io#platform-specific-behavior
806849
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
807850
self.inner.write(buf)
808851
}
809852

853+
/// Like `write`, except that it writes into a slice of buffers.
854+
///
855+
/// See [`Write::write_vectored`] docs for more info.
856+
///
857+
/// # Platform-specific behavior
858+
///
859+
/// This function currently corresponds to the `writev` function on Unix
860+
/// and falls back to the `write` implementation on Windows. Note that this
861+
/// [may change in the future][changes].
862+
///
863+
/// [changes]: io#platform-specific-behavior
810864
fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
811865
self.inner.write_vectored(bufs)
812866
}
813867

868+
/// Determines if `File` has an efficient `write_vectored` implementation.
869+
///
870+
/// See [`Write::is_write_vectored`] docs for more info.
871+
///
872+
/// # Platform-specific behavior
873+
///
874+
/// This function currently returns `true` on Unix an `false` on Windows.
875+
/// Note that this [may change in the future][changes].
876+
///
877+
/// [changes]: io#platform-specific-behavior
814878
#[inline]
815879
fn is_write_vectored(&self) -> bool {
816880
self.inner.is_write_vectored()
817881
}
818882

883+
/// Flushes the file, ensuring that all intermediately buffered contents
884+
/// reach their destination.
885+
///
886+
/// See [`Write::flush`] docs for more info.
887+
///
888+
/// # Platform-specific behavior
889+
///
890+
/// Since a `File` structure doesn't contain any buffers, this function is
891+
/// currently a no-op on Unix and Windows. Note that this [may change in
892+
/// the future][changes].
893+
///
894+
/// [changes]: io#platform-specific-behavior
819895
#[inline]
820896
fn flush(&mut self) -> io::Result<()> {
821897
self.inner.flush()

0 commit comments

Comments
 (0)
Failed to load comments.