15 releases (breaking)

0.10.0 May 23, 2023
0.9.0 Dec 12, 2021
0.8.0 Jun 13, 2020
0.7.0 Jun 12, 2019
0.0.5 Nov 21, 2015

#49 in Internationalization (i18n)

Download history 910/week @ 2024-07-20 1203/week @ 2024-07-27 1015/week @ 2024-08-03 1259/week @ 2024-08-10 1011/week @ 2024-08-17 1112/week @ 2024-08-24 1154/week @ 2024-08-31 875/week @ 2024-09-07 1068/week @ 2024-09-14 988/week @ 2024-09-21 1050/week @ 2024-09-28 893/week @ 2024-10-05 768/week @ 2024-10-12 795/week @ 2024-10-19 921/week @ 2024-10-26 1199/week @ 2024-11-02

3,838 downloads per month
Used in 19 crates (15 directly)

MIT license

350KB
674 lines

rust-pinyin

Build Status Crates.io Version Doc

汉语拼音转换工具 Rust 版

Installation

Add this to your Cargo.toml:

[dependencies]
pinyin = "0.10"

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 的拼音数据。

No runtime deps