Struct tokei::Language
[−]
[src]
pub struct Language { pub blanks: usize, pub code: usize, pub comments: usize, pub files: Vec<PathBuf>, pub stats: Vec<Stats>, pub lines: usize, pub line_comment: &'static [&'static str], pub multi_line: &'static [(&'static str, &'static str)], pub nested: bool, pub nested_comments: &'static [(&'static str, &'static str)], pub quotes: &'static [(&'static str, &'static str)], }
Struct representing a single Language.
Fields
blanks: usize
Number of blank lines.
code: usize
Number of lines of code.
comments: usize
Number of comments(both single, and multi-line)
files: Vec<PathBuf>
A collection of files to be analysed.
stats: Vec<Stats>
A collection of statistics based on the files provide from files
lines: usize
Number of total lines.
line_comment: &'static [&'static str]
A collection of single line comments in the language. ie. //
in Rust.
multi_line: &'static [(&'static str, &'static str)]
A collection of tuples representing the start and end of multi line
comments. ie. /* comment */
in Rust.
nested: bool
Whether the language supports nested multi line comments or not.
nested_comments: &'static [(&'static str, &'static str)]
A list of specific nested comments if this is empty all multi_line
comments count.
quotes: &'static [(&'static str, &'static str)]
A list of quotes by default it is ""
.
Methods
impl Language
[src]
fn new(
line_comment: &'static [&'static str],
multi_line: &'static [(&'static str, &'static str)]
) -> Self
[src]
line_comment: &'static [&'static str],
multi_line: &'static [(&'static str, &'static str)]
) -> Self
Constructs a new empty Language with the comments provided.
let mut rust = Language::new(&["//"], &[("/*", "*/")]);
fn new_blank() -> Self
[src]
Convience constructor for creating a language that has no commenting syntax.
let empty_array: &'static [&'static str] = &[]; let json = Language::new_blank(); assert_eq!(json.line_comment, empty_array);
fn new_c() -> Self
[src]
Convience constructor for creating a language that has the same commenting syntax as C like languages.
let rust = Language::new(&["//"], &[("/*", "*/")]); let c = Language::new_c(); assert_eq!(rust.line_comment, c.line_comment); assert_eq!(rust.multi_line, c.multi_line);
fn new_func() -> Self
[src]
Convience constructor for creating a language that has the same commenting syntax as ML like languages.
let ocaml = Language::new_multi(&[("(*", "*)")]); let coq = Language::new_func(); assert_eq!(ocaml.line_comment, coq.line_comment); assert_eq!(ocaml.multi_line, coq.multi_line);
fn new_html() -> Self
[src]
Convience constructor for creating a language that has the same commenting syntax as HTML like languages.
let xml = Language::new_multi(&[("<!--", "-->")]); let html = Language::new_html(); assert_eq!(xml.line_comment, html.line_comment); assert_eq!(xml.multi_line, html.multi_line);
fn new_hash() -> Self
[src]
Convience constructor for creating a language that has the same commenting syntax as Bash.
let bash = Language::new_single(&["#"]); let yaml = Language::new_hash(); assert_eq!(bash.line_comment, yaml.line_comment); assert_eq!(bash.multi_line, yaml.multi_line);
fn new_haskell() -> Self
[src]
Convience constructor for creating a language that has the same commenting syntax as Haskell.
let haskell = Language::new(&["--"], &[("{-", "-}")]).nested(); let idris = Language::new_haskell(); assert_eq!(haskell.line_comment, haskell.line_comment); assert_eq!(haskell.multi_line, haskell.multi_line);
fn new_multi(multi_line: &'static [(&'static str, &'static str)]) -> Self
[src]
Convience constructor for creating a language that only has multi line comments.
let mustache = Language::new_multi(&[("{{!", "}}")]);
fn new_pro() -> Self
[src]
Convience constructor for creating a language that has the same commenting syntax as Prolog.
let prolog = Language::new(&["%"], &[("/*", "*/")]); let oz = Language::new_pro(); assert_eq!(prolog.line_comment, oz.line_comment); assert_eq!(prolog.multi_line, oz.multi_line);
fn new_single(line_comment: &'static [&'static str]) -> Self
[src]
Convience constructor for creating a language that only has single line comments.
let haskell = Language::new_single(&["--"]);
fn is_empty(&self) -> bool
[src]
Checks if the language is empty. Empty meaning it doesn't have any statistics.
let rust = Language::new_c(); assert!(rust.is_empty());
fn is_blank(&self) -> bool
[src]
Checks if the language doesn't contain any comments.
let json = Language::new_blank(); assert!(json.is_blank());
fn nested(self) -> Self
[src]
Specify if the the language supports nested multi line comments.
let mut rust = Language::new(&["//"], &[("/*", "*/")]).nested(); assert!(rust.nested);
fn nested_comments(
self,
nested_comments: &'static [(&'static str, &'static str)]
) -> Self
[src]
self,
nested_comments: &'static [(&'static str, &'static str)]
) -> Self
Specify if the the language supports nested multi line comments.
And which are nested. If this is specified there is no need to
call the nested
function.
let mut d = Language::new(&["//"], &[("/*", "*/")]) .nested_comments(&[("/+", "+/")]); assert!(d.nested); assert_eq!(d.nested_comments, &[("/+", "+/")]);
fn set_quotes(self, quotes: &'static [(&'static str, &'static str)]) -> Self
[src]
Specifies if the language has a quotes to define a string where
the commenting syntax would be ignored. By default it is only
""
quotes that are ignored.
let mut javascript = Language::new(&["//"], &[("/*", "*/")]) .set_quotes(&[("\"", "\""), ("'", "'")]); assert!(!javascript.quotes.is_empty());
fn sort_by(&mut self, category: Sort)
[src]
Sorts each of the Stats
structs contained in the language based
on what category is provided
panic!'s if given the wrong category.
use tokei::{Language, Stats, Sort}; use std::path::PathBuf; let mut rust = Language::new_c(); let mut foo_stats = Stats::new(PathBuf::from("foo")); let mut bar_stats = Stats::new(PathBuf::from("bar")); foo_stats.code += 20; bar_stats.code += 10; rust.stats.push(bar_stats.clone()); rust.stats.push(foo_stats.clone()); assert_eq!(rust.stats, vec![bar_stats.clone(), foo_stats.clone()]); rust.sort_by(Sort::Code); assert_eq!(rust.stats, vec![foo_stats, bar_stats]);
Trait Implementations
impl Clone for Language
[src]
fn clone(&self) -> Language
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Debug for Language
[src]
impl AddAssign for Language
[src]
fn add_assign(&mut self, rhs: Self)
[src]
Performs the +=
operation.
impl AddAssign<Stats> for Language
[src]
fn add_assign(&mut self, rhs: Stats)
[src]
Performs the +=
operation.