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

#52 in Internationalization (i18n)

Download history 1649/week @ 2024-06-14 1834/week @ 2024-06-21 1652/week @ 2024-06-28 1034/week @ 2024-07-05 1087/week @ 2024-07-12 891/week @ 2024-07-19 1140/week @ 2024-07-26 1043/week @ 2024-08-02 1266/week @ 2024-08-09 992/week @ 2024-08-16 1108/week @ 2024-08-23 1159/week @ 2024-08-30 901/week @ 2024-09-06 1091/week @ 2024-09-13 996/week @ 2024-09-20 975/week @ 2024-09-27

4,221 downloads per month
Used in 16 crates (12 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