https://github.com/mozillazg/rust-pinyin
汉字转拼音
https://github.com/mozillazg/rust-pinyin
chinese hanzi hanzi-pinyin pinyin rust
Last synced: about 1 year ago
JSON representation
汉字转拼音
- Host: GitHub
- URL: https://github.com/mozillazg/rust-pinyin
- Owner: mozillazg
- License: mit
- Created: 2015-05-30T03:26:12.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2023-05-23T14:36:03.000Z (about 3 years ago)
- Last Synced: 2025-06-23T10:52:28.768Z (about 1 year ago)
- Topics: chinese, hanzi, hanzi-pinyin, pinyin, rust
- Language: Rust
- Homepage: https://docs.rs/pinyin/
- Size: 4.82 MB
- Stars: 213
- Watchers: 7
- Forks: 25
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# rust-pinyin
[](https://github.com/mozillazg/rust-pinyin/actions/workflows/ci.yml)
[](https://crates.io/crates/pinyin)
[](https://docs.rs/pinyin/)
汉语拼音转换工具 Rust 版
Installation
------------
Add this to your `Cargo.toml`:
```
[dependencies]
pinyin = "0.10"
```
Documentation
--------------
API documentation can be found here: https://docs.rs/pinyin/
Usage
------
```rust
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](https://github.com/mozillazg/pinyin-data) 的拼音数据。
Related Projects
-----------------
* [hotoo/pinyin](https://github.com/hotoo/pinyin): 汉语拼音转换工具 Node.js/JavaScript 版。
* [mozillazg/python-pinyin](https://github.com/mozillazg/python-pinyin): 汉语拼音转换工具 Python 版。
* [mozillazg/go-pinyin](https://github.com/mozillazg/go-pinyin): 汉语拼音转换工具 Go 版。