12 releases (7 breaking)

✓ Uses Rust 2018 edition

0.7.0 Jun 12, 2019
0.5.0 Apr 7, 2019
0.4.0 Sep 1, 2018
0.3.0 Apr 30, 2018
0.0.5 Nov 21, 2015

#5 in Internationalization (i18n)

Download history 427/week @ 2019-07-24 449/week @ 2019-07-31 682/week @ 2019-08-07 1854/week @ 2019-08-14 152/week @ 2019-08-21 54/week @ 2019-08-28 30/week @ 2019-09-04 19/week @ 2019-09-11 50/week @ 2019-09-18 35/week @ 2019-09-25 16/week @ 2019-10-02 35/week @ 2019-10-16 18/week @ 2019-10-23 31/week @ 2019-10-30

7,925 downloads per month

MIT license

350KB
674 lines

rust-pinyin

Build Status Build status Coverage Status Crates.io Version Doc

汉语拼音转换工具 Rust 版

Installation

Add this to your Cargo.toml:

[dependencies]
pinyin = "0.7"

Documentation

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

Usage

use pinyin::{ToPinyin, ToPinyinMulti};

fn main() {
    let hans = "中国人";

    // 无声调,输出 zhong guo ren
    for pinyin in hans.to_pinyin() {
        if let Some(pinyin) = pinyin {
            print!("{} ", pinyin.plain());
        }
    }
    println!();

    // 包含声调,输出 zhōng guó rén
    for pinyin in hans.to_pinyin() {
        if let Some(pinyin) = pinyin {
            print!("{} ", pinyin.with_tone());
        }
    }
    println!();

    // 声调用数字表示,输出 zho1ng guo2 re2n
    for pinyin in hans.to_pinyin() {
        if let Some(pinyin) = pinyin {
            print!("{} ", pinyin.with_tone_num());
        }
    }
    println!();

    // 多音字,输出
    // zho1ng zho4ng
    // guo2
    // re2n
    for multi in hans.to_pinyin_multi() {
        if let Some(multi) = multi {
            for pinyin in multi {
                print!("{} ", pinyin.with_tone_num());
            }
            println!();
        }
    }
}

Build

$ cargo build

Test

$ cargo test

Data

使用来自 pinyin-data 的拼音数据。

Related Projects

No runtime deps