comparison rust/hg-core/src/operations/debugdata.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 2e2033081274
comparison
equal deleted inserted replaced
46433:4b381dbbf8b7 46434:3e2d539d0d1a
13 pub enum DebugDataKind { 13 pub enum DebugDataKind {
14 Changelog, 14 Changelog,
15 Manifest, 15 Manifest,
16 } 16 }
17 17
18 /// Kind of error encountered by DebugData 18 /// Error type for `debug_data`
19 #[derive(Debug)] 19 #[derive(Debug)]
20 pub enum DebugDataErrorKind { 20 pub enum DebugDataError {
21 /// Error when reading a `revlog` file. 21 /// Error when reading a `revlog` file.
22 IoError(std::io::Error), 22 IoError(std::io::Error),
23 /// The revision has not been found. 23 /// The revision has not been found.
24 InvalidRevision, 24 InvalidRevision,
25 /// Found more than one revision whose ID match the requested prefix 25 /// Found more than one revision whose ID match the requested prefix
30 UnsuportedRevlogVersion(u16), 30 UnsuportedRevlogVersion(u16),
31 /// The `revlog` data format is not supported. 31 /// The `revlog` data format is not supported.
32 UnknowRevlogDataFormat(u8), 32 UnknowRevlogDataFormat(u8),
33 } 33 }
34 34
35 /// A DebugData error
36 #[derive(Debug)]
37 pub struct DebugDataError {
38 /// Kind of error encountered by DebugData
39 pub kind: DebugDataErrorKind,
40 }
41
42 impl From<DebugDataErrorKind> for DebugDataError {
43 fn from(kind: DebugDataErrorKind) -> Self {
44 DebugDataError { kind }
45 }
46 }
47
48 impl From<std::io::Error> for DebugDataError { 35 impl From<std::io::Error> for DebugDataError {
49 fn from(err: std::io::Error) -> Self { 36 fn from(err: std::io::Error) -> Self {
50 let kind = DebugDataErrorKind::IoError(err); 37 DebugDataError::IoError(err)
51 DebugDataError { kind }
52 } 38 }
53 } 39 }
54 40
55 impl From<RevlogError> for DebugDataError { 41 impl From<RevlogError> for DebugDataError {
56 fn from(err: RevlogError) -> Self { 42 fn from(err: RevlogError) -> Self {
57 match err { 43 match err {
58 RevlogError::IoError(err) => DebugDataErrorKind::IoError(err), 44 RevlogError::IoError(err) => DebugDataError::IoError(err),
59 RevlogError::UnsuportedVersion(version) => { 45 RevlogError::UnsuportedVersion(version) => {
60 DebugDataErrorKind::UnsuportedRevlogVersion(version) 46 DebugDataError::UnsuportedRevlogVersion(version)
61 } 47 }
62 RevlogError::InvalidRevision => { 48 RevlogError::InvalidRevision => DebugDataError::InvalidRevision,
63 DebugDataErrorKind::InvalidRevision 49 RevlogError::AmbiguousPrefix => DebugDataError::AmbiguousPrefix,
64 } 50 RevlogError::Corrupted => DebugDataError::CorruptedRevlog,
65 RevlogError::AmbiguousPrefix => {
66 DebugDataErrorKind::AmbiguousPrefix
67 }
68 RevlogError::Corrupted => DebugDataErrorKind::CorruptedRevlog,
69 RevlogError::UnknowDataFormat(format) => { 51 RevlogError::UnknowDataFormat(format) => {
70 DebugDataErrorKind::UnknowRevlogDataFormat(format) 52 DebugDataError::UnknowRevlogDataFormat(format)
71 } 53 }
72 } 54 }
73 .into()
74 } 55 }
75 } 56 }
76 57
77 /// Dump the contents data of a revision. 58 /// Dump the contents data of a revision.
78 pub fn debug_data( 59 pub fn debug_data(