Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,6 @@ required-features = ["compat"]
[[test]]
name = "special_pinyin"
required-features = ["with_tone_num_end", "heteronym"]

[dependencies]
hashbrown = { version = "0.16.1", features = ["alloc"] }
5 changes: 3 additions & 2 deletions src/compat.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#![allow(deprecated)]

use crate::{Pinyin, ToPinyin, ToPinyinMulti};
use std::collections::HashSet;
use alloc::string::{String, ToString};
use alloc::vec::Vec;

/// 拼音风格
#[deprecated = "请使用 `Pinyin` 的方法代替"]
Expand Down Expand Up @@ -86,7 +87,7 @@ pub fn pinyin(s: &str, a: &Args) -> Vec<Vec<String>> {
s.to_pinyin_multi()
.map(|multi| match multi {
Some(multi) => {
let mut set = HashSet::new();
let mut set = hashbrown::HashSet::new();
multi
.into_iter()
.map(|pinyin| apply_style(pinyin, &a.style))
Expand Down
8 changes: 6 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#![no_std]
use crate::data::CHAR_BLOCKS;
use std::convert::TryFrom;
use core::convert::TryFrom;

#[macro_use]
extern crate alloc;

#[cfg(feature = "compat")]
mod compat;
Expand All @@ -17,7 +21,7 @@ pub use crate::pinyin_multi::{PinyinMulti, PinyinMultiIter, PinyinMultiStrIter,
/// 将给定输入字符串的拼音通过给定映射函数后存入 `Vec` 中
///
/// 这个函数会跳过任何没有拼音的字符。本函数主要用于测试目的。
pub fn to_pinyin_vec<F>(input: &str, f: F) -> Vec<&'static str>
pub fn to_pinyin_vec<F>(input: &str, f: F) -> alloc::vec::Vec<&'static str>
where
F: Fn(Pinyin) -> &'static str,
{
Expand Down
2 changes: 1 addition & 1 deletion src/pinyin.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::data::PINYIN_DATA;
use crate::{get_block_and_index, PinyinData};
use std::str::Chars;
use core::str::Chars;

/// 单个字符的拼音信息
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
Expand Down
3 changes: 2 additions & 1 deletion src/pinyin_multi.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::data::{HETERONYM_TABLE, PINYIN_DATA};
use crate::{get_block_and_index, Pinyin, PinyinData};
use std::str::Chars;
use core::str::Chars;

/// 单个字符的多音字信息
///
Expand Down Expand Up @@ -184,6 +184,7 @@ mod tests {
#[test]
#[cfg(feature = "with_tone")]
fn str_to_pinyin_multi() {
use alloc::vec::Vec;
let actual = "还没"
.to_pinyin_multi()
.map(|multi| {
Expand Down