10 releases (5 breaking)

0.5.0 Apr 7, 2019
0.4.0 Sep 1, 2018
0.3.0 Apr 30, 2018
0.2.0 Oct 5, 2017
0.0.5 Nov 21, 2015

#8 in Internationalization (i18n)

Download history 337/week @ 2018-12-21 102/week @ 2018-12-28 253/week @ 2019-01-04 180/week @ 2019-01-11 242/week @ 2019-01-18 288/week @ 2019-01-25 70/week @ 2019-02-01 144/week @ 2019-02-08 353/week @ 2019-02-15 340/week @ 2019-02-22 402/week @ 2019-03-01 469/week @ 2019-03-08 996/week @ 2019-03-15 620/week @ 2019-03-22 15942/week @ 2019-03-29

6,725 downloads per month

MIT license

2.5MB
42K SLoC

rust-pinyin

Build Status Coverage Status Crates.io Version Doc

汉语拼音转换工具 Rust 版

Installation

Add this to your Cargo.toml:

[dependencies]
pinyin = "0.5"

and this to your crate root:

extern crate pinyin;

Documentation

API documentation can be found here: https://docs.rs/pinyin/

Usage

extern crate pinyin;

pub fn main() {
    let hans = "中国人";
    let mut args = pinyin::Args::new();

    // 默认输出 [["zhong"] ["guo"] ["ren"]]
    println!("{:?}",  pinyin::pinyin(hans, &args));
    // ["zhong", "guo", "ren"]
    println!("{:?}",  pinyin::lazy_pinyin(hans, &args));

    // 包含声调 [["zhōng"], ["guó"], ["rén"]]
    args.style = pinyin::Style::Tone;
    println!("{:?}",  pinyin::pinyin(hans, &args));

    // 声调用数字表示 [["zho1ng"] ["guo2"] ["re2n"]]
    args.style = pinyin::Style::Tone2;
    println!("{:?}",  pinyin::pinyin(hans, &args));

    // 开启多音字模式
    args = pinyin::Args::new();
    args.heteronym = true;
    // [["zhong", "zhong"] ["guo"] ["ren"]]
    println!("{:?}",  pinyin::pinyin(hans, &args));

    // [["zho1ng", "zho4ng"] ["guo2"] ["re2n"]]
    args.style = pinyin::Style::Tone2;
    println!("{:?}",  pinyin::pinyin(hans, &args));
}

Build

$ make build

Test

$ make test

Related Projects

No runtime deps