diff rust/hg-core/src/operations/cat.rs @ 46434:3e2d539d0d1a

rust: remove `FooError` structs with only `kind: FooErrorKind` enum field Use the enum directly as `FooError` instead. Differential Revision: https://phab.mercurial-scm.org/D9874
author Simon Sapin <simon.sapin@octobus.net>
date Tue, 26 Jan 2021 19:07:24 +0100
parents 4b381dbbf8b7
children b274aa2f20fd
line wrap: on
line diff
--- a/rust/hg-core/src/operations/cat.rs	Tue Jan 26 18:31:46 2021 +0100
+++ b/rust/hg-core/src/operations/cat.rs	Tue Jan 26 19:07:24 2021 +0100
@@ -20,9 +20,9 @@
 
 const METADATA_DELIMITER: [u8; 2] = [b'\x01', b'\n'];
 
-/// Kind of error encountered by `CatRev`
+/// Error type for `cat`
 #[derive(Debug)]
-pub enum CatRevErrorKind {
+pub enum CatRevError {
     /// Error when reading a `revlog` file.
     IoError(std::io::Error),
     /// The revision has not been found.
@@ -37,34 +37,20 @@
     UnknowRevlogDataFormat(u8),
 }
 
-/// A `CatRev` error
-#[derive(Debug)]
-pub struct CatRevError {
-    /// Kind of error encountered by `CatRev`
-    pub kind: CatRevErrorKind,
-}
-
-impl From<CatRevErrorKind> for CatRevError {
-    fn from(kind: CatRevErrorKind) -> Self {
-        CatRevError { kind }
-    }
-}
-
 impl From<RevlogError> for CatRevError {
     fn from(err: RevlogError) -> Self {
         match err {
-            RevlogError::IoError(err) => CatRevErrorKind::IoError(err),
+            RevlogError::IoError(err) => CatRevError::IoError(err),
             RevlogError::UnsuportedVersion(version) => {
-                CatRevErrorKind::UnsuportedRevlogVersion(version)
+                CatRevError::UnsuportedRevlogVersion(version)
             }
-            RevlogError::InvalidRevision => CatRevErrorKind::InvalidRevision,
-            RevlogError::AmbiguousPrefix => CatRevErrorKind::AmbiguousPrefix,
-            RevlogError::Corrupted => CatRevErrorKind::CorruptedRevlog,
+            RevlogError::InvalidRevision => CatRevError::InvalidRevision,
+            RevlogError::AmbiguousPrefix => CatRevError::AmbiguousPrefix,
+            RevlogError::Corrupted => CatRevError::CorruptedRevlog,
             RevlogError::UnknowDataFormat(format) => {
-                CatRevErrorKind::UnknowRevlogDataFormat(format)
+                CatRevError::UnknowRevlogDataFormat(format)
             }
         }
-        .into()
     }
 }
 
@@ -83,7 +69,7 @@
     let manifest = Manifest::open(repo)?;
     let changelog_entry = changelog.get_rev(rev)?;
     let manifest_node = Node::from_hex(&changelog_entry.manifest_node()?)
-        .map_err(|_| CatRevErrorKind::CorruptedRevlog)?;
+        .map_err(|_| CatRevError::CorruptedRevlog)?;
     let manifest_entry = manifest.get_node(manifest_node.into())?;
     let mut bytes = vec![];
 
@@ -96,7 +82,7 @@
                 let file_log =
                     Revlog::open(repo, &index_path, Some(&data_path))?;
                 let file_node = Node::from_hex(node_bytes)
-                    .map_err(|_| CatRevErrorKind::CorruptedRevlog)?;
+                    .map_err(|_| CatRevError::CorruptedRevlog)?;
                 let file_rev = file_log.get_node_rev(file_node.into())?;
                 let data = file_log.get_rev_data(file_rev)?;
                 if data.starts_with(&METADATA_DELIMITER) {