Mercurial > public > mercurial-scm > hg
diff rust/hg-core/src/lib.rs @ 46435:2e2033081274
rust: replace trivial `impl From ?` with `#[derive(derive_more::From)]`
Crate docs: https://jeltef.github.io/derive_more/derive_more/from.html
Differential Revision: https://phab.mercurial-scm.org/D9875
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Tue, 26 Jan 2021 20:05:37 +0100 |
parents | 4b381dbbf8b7 |
children | 39e9407820ac |
line wrap: on
line diff
--- a/rust/hg-core/src/lib.rs Tue Jan 26 19:07:24 2021 +0100 +++ b/rust/hg-core/src/lib.rs Tue Jan 26 20:05:37 2021 +0100 @@ -89,6 +89,7 @@ DirstatePackError::CorruptedEntry(e.to_string()) } } + #[derive(Debug, PartialEq)] pub enum DirstateMapError { PathNotFound(HgPathBuf), @@ -108,7 +109,7 @@ } } -#[derive(Debug)] +#[derive(Debug, derive_more::From)] pub enum DirstateError { Parse(DirstateParseError), Pack(DirstatePackError), @@ -116,24 +117,14 @@ IO(std::io::Error), } -impl From<DirstateParseError> for DirstateError { - fn from(e: DirstateParseError) -> Self { - DirstateError::Parse(e) - } -} - -impl From<DirstatePackError> for DirstateError { - fn from(e: DirstatePackError) -> Self { - DirstateError::Pack(e) - } -} - -#[derive(Debug)] +#[derive(Debug, derive_more::From)] pub enum PatternError { + #[from] Path(HgPathError), UnsupportedSyntax(String), UnsupportedSyntaxInFile(String, String, usize), TooLong(usize), + #[from] IO(std::io::Error), /// Needed a pattern that can be turned into a regex but got one that /// can't. This should only happen through programmer error. @@ -163,27 +154,3 @@ } } } - -impl From<DirstateMapError> for DirstateError { - fn from(e: DirstateMapError) -> Self { - DirstateError::Map(e) - } -} - -impl From<std::io::Error> for DirstateError { - fn from(e: std::io::Error) -> Self { - DirstateError::IO(e) - } -} - -impl From<std::io::Error> for PatternError { - fn from(e: std::io::Error) -> Self { - PatternError::IO(e) - } -} - -impl From<HgPathError> for PatternError { - fn from(e: HgPathError) -> Self { - PatternError::Path(e) - } -}