Crates.io | pinyin |
lib.rs | pinyin |
version | 0.10.0 |
source | src |
created_at | 2015-08-27 01:35:13.27245 |
updated_at | 2023-05-23 14:30:10.555148 |
description | Convert Chinese to pinyin |
homepage | https://github.com/mozillazg/rust-pinyin |
repository | https://github.com/mozillazg/rust-pinyin |
max_upload_size | |
id | 2931 |
size | 981,928 |
汉语拼音转换工具 Rust 版
Add this to your Cargo.toml
:
[dependencies]
pinyin = "0.10"
API documentation can be found here: https://docs.rs/pinyin/
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!();
}
}
}
$ cargo build
$ cargo test
使用来自 pinyin-data 的拼音数据。