From ec5db3c2016596dfd250fd72d4d0538944b46341 Mon Sep 17 00:00:00 2001 From: Aaron Power Date: Tue, 28 Aug 2018 21:42:00 +0100 Subject: [PATCH] Changed back to PathBuf, and corrected documentation --- src/language/language_type.hbs.rs | 10 +++++----- src/language/mod.rs | 8 ++++---- src/stats.rs | 9 ++++----- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/language/language_type.hbs.rs b/src/language/language_type.hbs.rs index 84bafffe2..933d52d1a 100644 --- a/src/language/language_type.hbs.rs +++ b/src/language/language_type.hbs.rs @@ -294,11 +294,11 @@ impl LanguageType { } } - /// Returns what nested comments the language has. (Currently only Go has + /// Returns what nested comments the language has. (Currently only D has /// any of this type.) /// ``` /// use tokei::LanguageType; - /// let lang = LanguageType::Go; + /// let lang = LanguageType::D; /// assert_eq!(lang.nested_comments(), &[("/+", "+/")]); /// ``` pub fn nested_comments(self) -> &'static [(&'static str, &'static str)] @@ -320,7 +320,7 @@ impl LanguageType { /// ``` /// use tokei::LanguageType; /// let lang = LanguageType::Rust; - /// assert_eq!(lang.quotes(), &[("\"", "\"")]); + /// assert_eq!(lang.quotes(), &[("r#\"", "\"#"), ("#\"", "\"#"), ("\"", "\"")]); /// ``` pub fn quotes(self) -> &'static [(&'static str, &'static str)] { match self { @@ -409,7 +409,7 @@ impl LanguageType { s }; - self.parse_from_str(entry, text) + self.parse_from_str(entry, &text) } /// Parses the text provided. Returning `Stats` on success. @@ -418,7 +418,7 @@ impl LanguageType { { let lines = text.lines(); - let mut stats = Stats::new(entry); + let mut stats = Stats::new(entry.path().to_owned()); let stats = if self.is_blank() { let count = lines.count(); diff --git a/src/language/mod.rs b/src/language/mod.rs index d880ca62b..14395405c 100644 --- a/src/language/mod.rs +++ b/src/language/mod.rs @@ -76,9 +76,9 @@ impl Language { /// ``` pub fn is_empty(&self) -> bool { self.code == 0 && - self.comments == 0 && - self.blanks == 0 && - self.lines == 0 + self.comments == 0 && + self.blanks == 0 && + self.lines == 0 } /// Sorts each of the `Stats` structs contained in the language based @@ -89,7 +89,7 @@ impl Language { Blanks => self.stats.sort_by(|a, b| b.blanks.cmp(&a.blanks)), Comments => self.stats.sort_by(|a, b| b.comments.cmp(&a.comments)), Code => self.stats.sort_by(|a, b| b.code.cmp(&a.code)), - Files => self.stats.sort_by(|a, b| a.name.path().cmp(&b.name.path())), + Files => self.stats.sort_by(|a, b| a.name.cmp(&b.name)), Lines => self.stats.sort_by(|a, b| b.lines.cmp(&a.lines)), } } diff --git a/src/stats.rs b/src/stats.rs index 341cde651..8bcd094df 100644 --- a/src/stats.rs +++ b/src/stats.rs @@ -1,6 +1,5 @@ use std::fmt; - -use ignore::DirEntry; +use std::path::PathBuf; /// A struct representing the statistics of a file. #[cfg_attr(feature = "io", derive(Deserialize, Serialize))] @@ -16,12 +15,12 @@ pub struct Stats { /// Total number of lines within the file. pub lines: usize, /// File name. - pub name: DirEntry, + pub name: PathBuf, } impl Stats { /// Create a new `Stats` from a `ignore::DirEntry`. - pub fn new(name: DirEntry) -> Self { + pub fn new(name: PathBuf) -> Self { Stats { blanks: 0, code: 0, @@ -56,7 +55,7 @@ macro_rules! display_stats { impl fmt::Display for Stats { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let name = self.name.path().to_string_lossy(); + let name = self.name.to_string_lossy(); let name_length = name.len(); let max_len = f.width().unwrap_or(25);