rust-pinyin

汉字转拼音

Github stars Tracking Chart

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

Main metrics

Overview
Name With Ownermozillazg/rust-pinyin
Primary LanguageRust
Program languageRust (Language Count: 2)
Platform
License:MIT License
所有者活动
Created At2015-05-30 03:26:12
Pushed At2023-05-23 14:36:03
Last Commit At2023-05-23 22:35:51
Release Count15
Last Release Namev0.10.0 (Posted on )
First Release Namev0.0.2 (Posted on 2015-08-30 10:56:17)
用户参与
Stargazers Count212
Watchers Count7
Fork Count25
Commits Count226
Has Issues Enabled
Issues Count31
Issue Open Count8
Pull Requests Count30
Pull Requests Open Count2
Pull Requests Close Count5
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private