##// END OF EJS Templates
rust: replace ToString impls with Display...
Simon Sapin -
r47173:6c778d20 default
parent child Browse files
Show More
@@ -33,6 +33,7 b' use rayon::prelude::*;'
33 use std::{
33 use std::{
34 borrow::Cow,
34 borrow::Cow,
35 collections::HashSet,
35 collections::HashSet,
36 fmt,
36 fs::{read_dir, DirEntry},
37 fs::{read_dir, DirEntry},
37 io::ErrorKind,
38 io::ErrorKind,
38 ops::Deref,
39 ops::Deref,
@@ -51,17 +52,16 b' pub enum BadType {'
51 Unknown,
52 Unknown,
52 }
53 }
53
54
54 impl ToString for BadType {
55 impl fmt::Display for BadType {
55 fn to_string(&self) -> String {
56 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
56 match self {
57 f.write_str(match self {
57 BadType::CharacterDevice => "character device",
58 BadType::CharacterDevice => "character device",
58 BadType::BlockDevice => "block device",
59 BadType::BlockDevice => "block device",
59 BadType::FIFO => "fifo",
60 BadType::FIFO => "fifo",
60 BadType::Socket => "socket",
61 BadType::Socket => "socket",
61 BadType::Directory => "directory",
62 BadType::Directory => "directory",
62 BadType::Unknown => "unknown",
63 BadType::Unknown => "unknown",
63 }
64 })
64 .to_string()
65 }
65 }
66 }
66 }
67
67
@@ -277,12 +277,12 b' pub enum StatusError {'
277
277
278 pub type StatusResult<T> = Result<T, StatusError>;
278 pub type StatusResult<T> = Result<T, StatusError>;
279
279
280 impl ToString for StatusError {
280 impl fmt::Display for StatusError {
281 fn to_string(&self) -> String {
281 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
282 match self {
282 match self {
283 StatusError::IO(e) => e.to_string(),
283 StatusError::IO(error) => error.fmt(f),
284 StatusError::Path(e) => e.to_string(),
284 StatusError::Path(error) => error.fmt(f),
285 StatusError::Pattern(e) => e.to_string(),
285 StatusError::Pattern(error) => error.fmt(f),
286 }
286 }
287 }
287 }
288 }
288 }
@@ -39,6 +39,7 b' pub use filepatterns::{'
39 PatternFileWarning, PatternSyntax,
39 PatternFileWarning, PatternSyntax,
40 };
40 };
41 use std::collections::HashMap;
41 use std::collections::HashMap;
42 use std::fmt;
42 use twox_hash::RandomXxHashBuilder64;
43 use twox_hash::RandomXxHashBuilder64;
43
44
44 /// This is a contract between the `micro-timer` crate and us, to expose
45 /// This is a contract between the `micro-timer` crate and us, to expose
@@ -59,14 +60,16 b' pub enum DirstateMapError {'
59 InvalidPath(HgPathError),
60 InvalidPath(HgPathError),
60 }
61 }
61
62
62 impl ToString for DirstateMapError {
63 impl fmt::Display for DirstateMapError {
63 fn to_string(&self) -> String {
64 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
64 match self {
65 match self {
65 DirstateMapError::PathNotFound(_) => {
66 DirstateMapError::PathNotFound(_) => {
66 "expected a value, found none".to_string()
67 f.write_str("expected a value, found none")
67 }
68 }
68 DirstateMapError::EmptyPath => "Overflow in dirstate.".to_string(),
69 DirstateMapError::EmptyPath => {
69 DirstateMapError::InvalidPath(e) => e.to_string(),
70 f.write_str("Overflow in dirstate.")
71 }
72 DirstateMapError::InvalidPath(path_error) => path_error.fmt(f),
70 }
73 }
71 }
74 }
72 }
75 }
@@ -91,25 +94,26 b' pub enum PatternError {'
91 NonRegexPattern(IgnorePattern),
94 NonRegexPattern(IgnorePattern),
92 }
95 }
93
96
94 impl ToString for PatternError {
97 impl fmt::Display for PatternError {
95 fn to_string(&self) -> String {
98 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
96 match self {
99 match self {
97 PatternError::UnsupportedSyntax(syntax) => {
100 PatternError::UnsupportedSyntax(syntax) => {
98 format!("Unsupported syntax {}", syntax)
101 write!(f, "Unsupported syntax {}", syntax)
99 }
102 }
100 PatternError::UnsupportedSyntaxInFile(syntax, file_path, line) => {
103 PatternError::UnsupportedSyntaxInFile(syntax, file_path, line) => {
101 format!(
104 write!(
105 f,
102 "{}:{}: unsupported syntax {}",
106 "{}:{}: unsupported syntax {}",
103 file_path, line, syntax
107 file_path, line, syntax
104 )
108 )
105 }
109 }
106 PatternError::TooLong(size) => {
110 PatternError::TooLong(size) => {
107 format!("matcher pattern is too long ({} bytes)", size)
111 write!(f, "matcher pattern is too long ({} bytes)", size)
108 }
112 }
109 PatternError::IO(e) => e.to_string(),
113 PatternError::IO(error) => error.fmt(f),
110 PatternError::Path(e) => e.to_string(),
114 PatternError::Path(error) => error.fmt(f),
111 PatternError::NonRegexPattern(pattern) => {
115 PatternError::NonRegexPattern(pattern) => {
112 format!("'{:?}' cannot be turned into a regex", pattern)
116 write!(f, "'{:?}' cannot be turned into a regex", pattern)
113 }
117 }
114 }
118 }
115 }
119 }
@@ -47,57 +47,68 b' pub enum HgPathError {'
47 },
47 },
48 }
48 }
49
49
50 impl ToString for HgPathError {
50 impl fmt::Display for HgPathError {
51 fn to_string(&self) -> String {
51 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
52 match self {
52 match self {
53 HgPathError::LeadingSlash(bytes) => {
53 HgPathError::LeadingSlash(bytes) => {
54 format!("Invalid HgPath '{:?}': has a leading slash.", bytes)
54 write!(f, "Invalid HgPath '{:?}': has a leading slash.", bytes)
55 }
55 }
56 HgPathError::ConsecutiveSlashes {
56 HgPathError::ConsecutiveSlashes {
57 bytes,
57 bytes,
58 second_slash_index: pos,
58 second_slash_index: pos,
59 } => format!(
59 } => write!(
60 f,
60 "Invalid HgPath '{:?}': consecutive slashes at pos {}.",
61 "Invalid HgPath '{:?}': consecutive slashes at pos {}.",
61 bytes, pos
62 bytes, pos
62 ),
63 ),
63 HgPathError::ContainsNullByte {
64 HgPathError::ContainsNullByte {
64 bytes,
65 bytes,
65 null_byte_index: pos,
66 null_byte_index: pos,
66 } => format!(
67 } => write!(
68 f,
67 "Invalid HgPath '{:?}': contains null byte at pos {}.",
69 "Invalid HgPath '{:?}': contains null byte at pos {}.",
68 bytes, pos
70 bytes, pos
69 ),
71 ),
70 HgPathError::DecodeError(bytes) => {
72 HgPathError::DecodeError(bytes) => write!(
71 format!("Invalid HgPath '{:?}': could not be decoded.", bytes)
73 f,
72 }
74 "Invalid HgPath '{:?}': could not be decoded.",
75 bytes
76 ),
73 HgPathError::EndsWithSlash(path) => {
77 HgPathError::EndsWithSlash(path) => {
74 format!("Audit failed for '{}': ends with a slash.", path)
78 write!(f, "Audit failed for '{}': ends with a slash.", path)
75 }
79 }
76 HgPathError::ContainsIllegalComponent(path) => format!(
80 HgPathError::ContainsIllegalComponent(path) => write!(
81 f,
77 "Audit failed for '{}': contains an illegal component.",
82 "Audit failed for '{}': contains an illegal component.",
78 path
83 path
79 ),
84 ),
80 HgPathError::InsideDotHg(path) => format!(
85 HgPathError::InsideDotHg(path) => write!(
86 f,
81 "Audit failed for '{}': is inside the '.hg' folder.",
87 "Audit failed for '{}': is inside the '.hg' folder.",
82 path
88 path
83 ),
89 ),
84 HgPathError::IsInsideNestedRepo {
90 HgPathError::IsInsideNestedRepo {
85 path,
91 path,
86 nested_repo: nested,
92 nested_repo: nested,
87 } => format!(
93 } => {
94 write!(f,
88 "Audit failed for '{}': is inside a nested repository '{}'.",
95 "Audit failed for '{}': is inside a nested repository '{}'.",
89 path, nested
96 path, nested
90 ),
97 )
91 HgPathError::TraversesSymbolicLink { path, symlink } => format!(
98 }
99 HgPathError::TraversesSymbolicLink { path, symlink } => write!(
100 f,
92 "Audit failed for '{}': traverses symbolic link '{}'.",
101 "Audit failed for '{}': traverses symbolic link '{}'.",
93 path, symlink
102 path, symlink
94 ),
103 ),
95 HgPathError::NotFsCompliant(path) => format!(
104 HgPathError::NotFsCompliant(path) => write!(
105 f,
96 "Audit failed for '{}': cannot be turned into a \
106 "Audit failed for '{}': cannot be turned into a \
97 filesystem path.",
107 filesystem path.",
98 path
108 path
99 ),
109 ),
100 HgPathError::NotUnderRoot { path, root } => format!(
110 HgPathError::NotUnderRoot { path, root } => write!(
111 f,
101 "Audit failed for '{}': not under root {}.",
112 "Audit failed for '{}': not under root {}.",
102 path.display(),
113 path.display(),
103 root.display()
114 root.display()
General Comments 0
You need to be logged in to leave comments. Login now