pub struct Language {
pub blanks: usize,
pub code: usize,
pub comments: usize,
pub reports: Vec<Report>,
pub children: BTreeMap<LanguageType, Vec<Report>>,
pub inaccurate: bool,
}
Expand description
A struct representing statistics about a single Language.
Fields§
§blanks: usize
The total number of blank lines.
code: usize
The total number of lines of code.
comments: usize
The total number of comments(both single, and multi-line)
reports: Vec<Report>
A collection of statistics of individual files.
children: BTreeMap<LanguageType, Vec<Report>>
A map of any languages found in the reports.
inaccurate: bool
Whether this language had problems with file parsing
Implementations§
source§impl Language
impl Language
sourcepub fn new() -> Self
pub fn new() -> Self
Constructs a new empty Language with the comments provided.
let mut rust = Language::new();
sourcepub fn add_report(&mut self, report: Report)
pub fn add_report(&mut self, report: Report)
Add a Report
to the Language. This will not update the totals in the
Language struct.
sourcepub fn mark_inaccurate(&mut self)
pub fn mark_inaccurate(&mut self)
Marks this language as possibly not reflecting correct stats.
sourcepub fn summarise(&self) -> Language
pub fn summarise(&self) -> Language
Creates a new Language
from self
, which is a summarised version
of the language that doesn’t contain any children. It will count
non-blank lines in child languages as code unless the child language is
considered “literate” then it will be counted as comments.
sourcepub fn total(&mut self)
pub fn total(&mut self)
Totals up the statistics of the Stat
structs currently contained in
the language.
use std::{collections::BTreeMap, path::PathBuf};
use tokei::Language;
let mut language = Language::new();
// Add stats...
assert_eq!(0, language.lines());
language.total();
assert_eq!(10, language.lines());
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Checks if the language is empty. Empty meaning it doesn’t have any statistics.
let rust = Language::new();
assert!(rust.is_empty());
sourcepub fn sort_by(&mut self, category: Sort)
pub fn sort_by(&mut self, category: Sort)
Sorts each of the Report
s contained in the language based
on what category is provided.
use std::{collections::BTreeMap, path::PathBuf};
use tokei::{Language, Sort};
let mut language = Language::new();
// Add stats...
language.sort_by(Sort::Lines);
assert_eq!(20, language.reports[0].stats.lines());
language.sort_by(Sort::Code);
assert_eq!(8, language.reports[0].stats.code);
Trait Implementations§
source§impl AddAssign<Language> for Language
impl AddAssign<Language> for Language
source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+=
operation. Read more