Skip to content

Commit e332f3b

Browse files
authored
Rollup merge of #95294 - sourcefrog:doc-copy, r=dtolnay
Document Linux kernel handoff in std::io::copy and std::fs::copy
2 parents 1446d17 + cfee2ed commit e332f3b

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

library/std/src/fs.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -1729,11 +1729,17 @@ pub fn rename<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<()>
17291729
/// This function currently corresponds to the `open` function in Unix
17301730
/// with `O_RDONLY` for `from` and `O_WRONLY`, `O_CREAT`, and `O_TRUNC` for `to`.
17311731
/// `O_CLOEXEC` is set for returned file descriptors.
1732+
///
1733+
/// On Linux (including Android), this function attempts to use `copy_file_range(2)`,
1734+
/// and falls back to reading and writing if that is not possible.
1735+
///
17321736
/// On Windows, this function currently corresponds to `CopyFileEx`. Alternate
17331737
/// NTFS streams are copied but only the size of the main stream is returned by
1734-
/// this function. On MacOS, this function corresponds to `fclonefileat` and
1735-
/// `fcopyfile`.
1736-
/// Note that, this [may change in the future][changes].
1738+
/// this function.
1739+
///
1740+
/// On MacOS, this function corresponds to `fclonefileat` and `fcopyfile`.
1741+
///
1742+
/// Note that platform-specific behavior [may change in the future][changes].
17371743
///
17381744
/// [changes]: io#platform-specific-behavior
17391745
///

library/std/src/io/copy.rs

+10
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ use crate::mem::MaybeUninit;
3939
/// Ok(())
4040
/// }
4141
/// ```
42+
///
43+
/// # Platform-specific behavior
44+
///
45+
/// On Linux (including Android), this function uses `copy_file_range(2)`,
46+
/// `sendfile(2)` or `splice(2)` syscalls to move data directly between file
47+
/// descriptors if possible.
48+
///
49+
/// Note that platform-specific behavior [may change in the future][changes].
50+
///
51+
/// [changes]: crate::io#platform-specific-behavior
4252
#[stable(feature = "rust1", since = "1.0.0")]
4353
pub fn copy<R: ?Sized, W: ?Sized>(reader: &mut R, writer: &mut W) -> Result<u64>
4454
where

0 commit comments

Comments
 (0)