OpenCC

Struct OpenCC 

Source
pub struct OpenCC { /* private fields */ }
Expand description

核心的 OpenCC 转换器

Implementations§

Source§

impl OpenCC

Source

pub fn new<P: AsRef<Path>>(config_path: P) -> Result<Self>

从配置文件创建一个新的 OpenCC 实例。 解析 JSON 配置文件,加载所有必需的词典,并构建转换流程。

§参数
  • config_path: 指向主 JSON 配置文件(例如 s2t.json)的路径
§返回

一个 Result,其中包含新的 OpenCC 实例,或者在加载失败时返回错误

Source

pub fn from_config(config_enum: BuiltinConfig) -> Result<Self>

从内置的配置创建 OpenCC 实例。

§示例
use ferrous_opencc::{OpenCC, config::BuiltinConfig, error::Result};

fn main() -> Result<()> {
    let opencc = OpenCC::from_config(BuiltinConfig::S2t)?;
    Ok(())
}
Source

pub fn convert(&self, input: &str) -> String

根据加载的配置转换字符串

§参数
  • input: 需要转换的字符串
§返回

转换后的字符串

Source

pub fn name(&self) -> &str

返回当前加载的配置名称

Auto Trait Implementations§

§

impl Freeze for OpenCC

§

impl !RefUnwindSafe for OpenCC

§

impl Send for OpenCC

§

impl Sync for OpenCC

§

impl Unpin for OpenCC

§

impl !UnwindSafe for OpenCC

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.