pinyin 0.0.4

Convert Chinese to pinyin
docs.rs failed to build pinyin-0.0.4
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: pinyin-0.10.0

rust-pinyin

Build Status Coverage Status Crates.io Version Doc

汉语拼音转换工具 Rust 版

Installation

Add this to your Cargo.toml:

[dependencies]
pinyin = "*"

and this to your crate root:

extern crate pinyin;

Documentation

API documentation can be found here: http://mozillazg.com/rust-pinyin/

Usage

extern crate pinyin;

pub fn main() {
    let hans = "中国人";
    let mut args = pinyin::Args::new();

    // 默认输出 [["zhong"] ["guo"] ["ren"]]
    println!("{:?}",  pinyin::pinyin(hans, &args));

    // 包含声调 [["zh\u{14d}ng"], ["gu\u{f3}"], ["r\u{e9}n"]]
    args.style = pinyin::Style::Tone;
    println!("{:?}",  pinyin::pinyin(hans, &args));

    // 声调用数字表示 [["zho1ng"] ["guo2"] ["re2n"]]
    args.style = pinyin::Style::Tone2;
    println!("{:?}",  pinyin::pinyin(hans, &args));

    // 开启多音字模式
    args = pinyin::Args::new();
    args.heteronym = true;
    // [["zhong", "zhong"] ["guo"] ["ren"]]
    println!("{:?}",  pinyin::pinyin(hans, &args));
    // [["zho1ng", "zho4ng"] ["guo2"] ["re2n"]]
    args.style = pinyin::Style::Tone2;
    println!("{:?}",  pinyin::pinyin(hans, &args));
}

Related Projects