chars_counter

Crates.iochars_counter
lib.rschars_counter
version0.1.1
sourcesrc
created_at2021-12-03 11:08:16.801663
updated_at2021-12-12 03:36:14.263754
descriptionThe trait that implements character counting for the &str type
homepage
repositoryhttps://github.com/voidsand/chars_counter
max_upload_size
id491676
size9,517
Voidsand (voidsand)

documentation

README

Chars Counter

The trait that implements character counting for the &str type.

Quick Start

use chars_counter::{ICharsCounter, ICharCounterExt};

let str = "Hello world!";
let result = str.count_chars();
// result = [CharsCounter { character: 'l', count: 3 }, CharsCounter { character: 'o', count: 2 }, CharsCounter { character: ' ', count: 1 }, CharsCounter { character: '!', count: 1 }, CharsCounter { character: 'H', count: 1 }, CharsCounter { character: 'd', count: 1 }, CharsCounter { character: 'e', count: 1 }, CharsCounter { character: 'r', count: 1 }, CharsCounter { character: 'w', count: 1 }]

// You can also use like this:
let result = str.count_chars_numeric();
let result = str.count_chars_alphabetic();
let result = str.count_chars_chinese();
// ...... Others you can try by yourself.
// if those can't meet your needs, you can custom your own rules by
let result = str.count_chars_filter(|x| *x != ' '); // ignore whitespaces.

// More features:
let result = str.count_chars().most_chars();
// result = [CharsCounter { character: 'l', count: 3 }]
let result = str.count_chars().least_chars();
// result = [CharsCounter { character: ' ', count: 1 }, CharsCounter { character: '!', count: 1 }, CharsCounter { character: 'H', count: 1 }, CharsCounter { character: 'd', count: 1 }, CharsCounter { character: 'e', count: 1 }, CharsCounter { character: 'r', count: 1 }, CharsCounter { character: 'w', count: 1 }]
let result = str.count_chars().find_by_char('l');
// result = Some(CharsCounter { character: 'l', count: 3 })
let result = str.count_chars().find_by_num(2);
// result = [CharsCounter { character: 'o', count: 2 }]
let result = str.count_chars().least_chars().find_by_char('H');
// result = Some(CharsCounter { character: 'H', count: 1 })
Commit count: 1

cargo fmt