Mercurial > public > mercurial-scm > hg-stable
comparison rust/hg-core/src/errors.rs @ 48464:abeae090ce67
rust: Add Vfs::write_atomic
This method writes to a temporary file then renames in place
Differential Revision: https://phab.mercurial-scm.org/D11836
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Mon, 29 Nov 2021 18:46:04 +0100 |
parents | cf5f8da2244c |
children | 3f86ee422095 |
comparison
equal
deleted
inserted
replaced
48463:5734b03ecf3e | 48464:abeae090ce67 |
---|---|
149 /// example.txt” instead of just “File not found”. | 149 /// example.txt” instead of just “File not found”. |
150 /// | 150 /// |
151 /// Converts a `Result` with `std::io::Error` into one with `HgError`. | 151 /// Converts a `Result` with `std::io::Error` into one with `HgError`. |
152 fn when_reading_file(self, path: &std::path::Path) -> Result<T, HgError>; | 152 fn when_reading_file(self, path: &std::path::Path) -> Result<T, HgError>; |
153 | 153 |
154 fn when_writing_file(self, path: &std::path::Path) -> Result<T, HgError>; | |
155 | |
154 fn with_context( | 156 fn with_context( |
155 self, | 157 self, |
156 context: impl FnOnce() -> IoErrorContext, | 158 context: impl FnOnce() -> IoErrorContext, |
157 ) -> Result<T, HgError>; | 159 ) -> Result<T, HgError>; |
158 } | 160 } |
159 | 161 |
160 impl<T> IoResultExt<T> for std::io::Result<T> { | 162 impl<T> IoResultExt<T> for std::io::Result<T> { |
161 fn when_reading_file(self, path: &std::path::Path) -> Result<T, HgError> { | 163 fn when_reading_file(self, path: &std::path::Path) -> Result<T, HgError> { |
162 self.with_context(|| IoErrorContext::ReadingFile(path.to_owned())) | 164 self.with_context(|| IoErrorContext::ReadingFile(path.to_owned())) |
165 } | |
166 | |
167 fn when_writing_file(self, path: &std::path::Path) -> Result<T, HgError> { | |
168 self.with_context(|| IoErrorContext::WritingFile(path.to_owned())) | |
163 } | 169 } |
164 | 170 |
165 fn with_context( | 171 fn with_context( |
166 self, | 172 self, |
167 context: impl FnOnce() -> IoErrorContext, | 173 context: impl FnOnce() -> IoErrorContext, |