Mercurial > public > mercurial-scm > hg
comparison rust/hg-core/src/utils/hg_path.rs @ 44973:26114bd6ec60
rust: do a clippy pass
This is the result of running `cargo clippy` on hg-core/hg-cpython and fixing
the lints that do not require too much code churn (and would warrant a separate
commit/complete refactor) and only come from our code (a lot of warnings in
hg-cpython come from `rust-cpython`).
Most of those were good lints, two of them was the linter not being smart
enough (or compiler to get up to `clippy`'s level depending on how you see it).
Maybe in the future we could have `clippy` be part of the CI.
Differential Revision: https://phab.mercurial-scm.org/D8635
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Mon, 15 Jun 2020 18:26:40 +0200 |
parents | 0e9ac3968b56 |
children | 2d5dfc8fed55 |
comparison
equal
deleted
inserted
replaced
44962:ef8dcee272ac | 44973:26114bd6ec60 |
---|---|
206 ), | 206 ), |
207 } | 207 } |
208 } | 208 } |
209 pub fn join<T: ?Sized + AsRef<Self>>(&self, other: &T) -> HgPathBuf { | 209 pub fn join<T: ?Sized + AsRef<Self>>(&self, other: &T) -> HgPathBuf { |
210 let mut inner = self.inner.to_owned(); | 210 let mut inner = self.inner.to_owned(); |
211 if inner.len() != 0 && inner.last() != Some(&b'/') { | 211 if !inner.is_empty() && inner.last() != Some(&b'/') { |
212 inner.push(b'/'); | 212 inner.push(b'/'); |
213 } | 213 } |
214 inner.extend(other.as_ref().bytes()); | 214 inner.extend(other.as_ref().bytes()); |
215 HgPathBuf::from_bytes(&inner) | 215 HgPathBuf::from_bytes(&inner) |
216 } | 216 } |
313 | 313 |
314 /// Checks for errors in the path, short-circuiting at the first one. | 314 /// Checks for errors in the path, short-circuiting at the first one. |
315 /// This generates fine-grained errors useful for debugging. | 315 /// This generates fine-grained errors useful for debugging. |
316 /// To simply check if the path is valid during tests, use `is_valid`. | 316 /// To simply check if the path is valid during tests, use `is_valid`. |
317 pub fn check_state(&self) -> Result<(), HgPathError> { | 317 pub fn check_state(&self) -> Result<(), HgPathError> { |
318 if self.len() == 0 { | 318 if self.is_empty() { |
319 return Ok(()); | 319 return Ok(()); |
320 } | 320 } |
321 let bytes = self.as_bytes(); | 321 let bytes = self.as_bytes(); |
322 let mut previous_byte = None; | 322 let mut previous_byte = None; |
323 | 323 |
364 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | 364 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
365 write!(f, "{}", String::from_utf8_lossy(&self.inner)) | 365 write!(f, "{}", String::from_utf8_lossy(&self.inner)) |
366 } | 366 } |
367 } | 367 } |
368 | 368 |
369 #[derive(Eq, Ord, Clone, PartialEq, PartialOrd, Hash)] | 369 #[derive(Default, Eq, Ord, Clone, PartialEq, PartialOrd, Hash)] |
370 pub struct HgPathBuf { | 370 pub struct HgPathBuf { |
371 inner: Vec<u8>, | 371 inner: Vec<u8>, |
372 } | 372 } |
373 | 373 |
374 impl HgPathBuf { | 374 impl HgPathBuf { |
375 pub fn new() -> Self { | 375 pub fn new() -> Self { |
376 Self { inner: Vec::new() } | 376 Default::default() |
377 } | 377 } |
378 pub fn push(&mut self, byte: u8) { | 378 pub fn push(&mut self, byte: u8) { |
379 self.inner.push(byte); | 379 self.inner.push(byte); |
380 } | 380 } |
381 pub fn from_bytes(s: &[u8]) -> HgPathBuf { | 381 pub fn from_bytes(s: &[u8]) -> HgPathBuf { |
382 HgPath::new(s).to_owned() | 382 HgPath::new(s).to_owned() |
383 } | 383 } |
384 pub fn into_vec(self) -> Vec<u8> { | 384 pub fn into_vec(self) -> Vec<u8> { |
385 self.inner | 385 self.inner |
386 } | |
387 pub fn as_ref(&self) -> &[u8] { | |
388 self.inner.as_ref() | |
389 } | 386 } |
390 } | 387 } |
391 | 388 |
392 impl fmt::Debug for HgPathBuf { | 389 impl fmt::Debug for HgPathBuf { |
393 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | 390 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |