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