| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::{selfrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/, Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#}; |
| 2 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::{selfrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/, Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#, Seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#, SeekFromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/SeekFrom#}; |
| 3 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#; |
| 4 | |
| 5 | /// Tries to clone the file with [crate::clone_file], falling back to [fs::copy] on error |
| 6 | /// |
| 7 | /// Returns `Ok(None)` on successful clone, `Ok(Some(copied_byte_count))` on successful [fs::copy]. |
| 8 | pub fn clone_or_copy_filerust-analyzer cargo clone-file 0.1.0 common/clone_or_copy_file().<P: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>, Q: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>>( |
| 9 | src: P, |
| 10 | dest: Q, |
| 11 | ) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<u64>> { |
| 12 | if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(_) = craterust-analyzer cargo clone-file 0.1.0 crate/::clone_filerust-analyzer cargo clone-file 0.1.0 linux/clone_file().(&src, &dest) { |
| 13 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) |
| 14 | } else { |
| 15 | fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::copyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/copy().(&src, &dest).and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]and_then().(|x| Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(x))) |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | /// Tries to clone a range of bytes to another file, falling back to [copy_file_range] on error |
| 20 | /// |
| 21 | /// Returns `Ok(None)` on successful clone, `Ok(Some(copied_byte_count))` on successful naive copy. |
| 22 | pub fn clone_or_copy_file_rangerust-analyzer cargo clone-file 0.1.0 common/clone_or_copy_file_range().<P: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>, Q: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>>( |
| 23 | src: P, |
| 24 | src_offset: u64, |
| 25 | src_length: u64, |
| 26 | dest: Q, |
| 27 | dest_offset: u64, |
| 28 | ) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<u64>> { |
| 29 | if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(_) = craterust-analyzer cargo clone-file 0.1.0 crate/::clone_file_rangerust-analyzer cargo clone-file 0.1.0 linux/clone_file_range().(&src, src_offset, src_length, &dest, dest_offset) { |
| 30 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) |
| 31 | } else { |
| 32 | todorust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/todo!!() |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | /// Naively copy a range of bytes from one file to another |
| 37 | /// |
| 38 | /// This function is mainly implemented as a fallback for [clone_or_copy_file_range]. |
| 39 | /// |
| 40 | /// Returns `Ok(copied_byte_count)` on success. |
| 41 | pub fn copy_file_rangerust-analyzer cargo clone-file 0.1.0 common/copy_file_range().<P: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>, Q: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>>( |
| 42 | src: P, |
| 43 | src_offset: u64, |
| 44 | src_length: u64, |
| 45 | dest: Q, |
| 46 | dest_offset: u64, |
| 47 | ) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<u64> { |
| 48 | let mut src_file = Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::openrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]open().(src)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 49 | let mut dest_file = Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::optionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]options().().writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]write().(true).createrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]create().(true).openrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]open().(dest)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 50 | |
| 51 | src_file.seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File][Seek]seek().(SeekFromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/SeekFrom#::Startrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/SeekFrom#Start#(src_offset))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 52 | let mut src_file = src_file.takerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#take().(src_length); |
| 53 | |
| 54 | dest_file.seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File][Seek]seek().(SeekFromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/SeekFrom#::Startrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/SeekFrom#Start#(dest_offset))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 55 | |
| 56 | iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::copyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/copy/copy().(&mut src_file, &mut dest_file) |
| 57 | } |