Skip to content

Commit

Permalink
Changed back to PathBuf, and corrected documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Power committed Aug 28, 2018
1 parent bf53af8 commit ec5db3c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
10 changes: 5 additions & 5 deletions src/language/language_type.hbs.rs
Expand Up @@ -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)]
Expand All @@ -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 {
Expand Down Expand Up @@ -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.
Expand All @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions src/language/mod.rs
Expand Up @@ -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
Expand All @@ -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)),
}
}
Expand Down
9 changes: 4 additions & 5 deletions 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))]
Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit ec5db3c

Please sign in to comment.