[][src]Struct tokei::Language

pub struct Language {
    pub blanks: usize,
    pub code: usize,
    pub comments: usize,
    pub lines: usize,
    pub stats: Vec<Stats>,
    pub inaccurate: bool,
}

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)

lines: usize

The total number of total lines.

stats: Vec<Stats>

A collection of statistics of individual files.

inaccurate: bool

Whether this language had problems with file parsing

Methods

impl Language[src]

pub fn new() -> Self[src]

Constructs a new empty Language with the comments provided.

let mut rust = Language::new();

pub fn add_stat(&mut self, stat: Stats)[src]

Add a Stat to the Language. This will not update the totals in the Language struct.

use std::path::PathBuf;
use tokei::{Language, Stats};

let mut language = Language::new();

language.add_stat(Stats {
    lines: 10,
    code: 4,
    comments: 3,
    blanks: 3,
    name: PathBuf::from("test.rs"),
});

pub fn mark_inaccurate(&mut self)[src]

Marks this language as possibly not reflecting correct stats.

pub fn total(&mut self)[src]

Totals up the statistics of the Stat structs currently contained in the language.

use std::path::PathBuf;
use tokei::{Language, Stats};

let mut language = Language::new();

language.add_stat(Stats {
    lines: 10,
    code: 4,
    comments: 3,
    blanks: 3,
    name: PathBuf::from("test.rs"),
});

assert_eq!(0, language.lines);

language.total();

assert_eq!(10, language.lines);

pub fn is_empty(&self) -> bool[src]

Checks if the language is empty. Empty meaning it doesn't have any statistics.

let rust = Language::new();

assert!(rust.is_empty());

pub fn sort_by(&mut self, category: Sort)[src]

Sorts each of the Stats structs contained in the language based on what category is provided.

use std::path::PathBuf;
use tokei::{Language, Sort, Stats};

let mut language = Language::new();

language.add_stat(Stats {
    lines: 10,
    code: 8,
    comments: 0,
    blanks: 2,
    name: PathBuf::from("test.rs"),
});

language.add_stat(Stats {
    lines: 20,
    code: 4,
    comments: 13,
    blanks: 3,
    name: PathBuf::from("testsuite.rs"),
});

language.sort_by(Sort::Lines);
assert_eq!(20, language.stats[0].lines);

language.sort_by(Sort::Code);
assert_eq!(8, language.stats[0].code);

Trait Implementations

impl AddAssign<Language> for Language[src]

impl Clone for Language[src]

impl Debug for Language[src]

impl Default for Language[src]

impl<'de> Deserialize<'de> for Language[src]

impl PartialEq<Language> for Language[src]

impl Serialize for Language[src]

impl StructuralPartialEq for Language[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.