Skip to content

Commit

Permalink
refactor!: bump MSRV to 1.83 and fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
kanru committed Dec 12, 2024
1 parent 9d7ab41 commit 4084c10
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 94 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description = "The Chewing (酷音) intelligent Zhuyin input method."
documentation = "https://docs.rs/chewing"
license = "LGPL-2.1-or-later"
version = "0.9.1"
rust-version = "1.77.0"
rust-version = "1.83.0"
edition = "2021"

include = [
Expand Down
2 changes: 1 addition & 1 deletion capi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "chewing_capi"
description = "The Chewing (酷音) intelligent Zhuyin input method."
license = "LGPL-2.1-or-later"
version = "0.9.1"
rust-version = "1.77"
rust-version = "1.83.0"
edition = "2021"

[lib]
Expand Down
84 changes: 39 additions & 45 deletions capi/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,24 +290,24 @@ pub unsafe extern "C" fn chewing_config_has_option(
let cstr = unsafe { CStr::from_ptr(name) };
let name = cstr.to_string_lossy();

let ret = match name.as_ref() {
let ret = matches!(
name.as_ref(),
"chewing.user_phrase_add_direction"
| "chewing.disable_auto_learn_phrase"
| "chewing.auto_shift_cursor"
| "chewing.candidates_per_page"
| "chewing.language_mode"
| "chewing.easy_symbol_input"
| "chewing.esc_clear_all_buffer"
| "chewing.keyboard_type"
| "chewing.auto_commit_threshold"
| "chewing.phrase_choice_rearward"
| "chewing.selection_keys"
| "chewing.character_form"
| "chewing.space_is_select_key"
| "chewing.conversion_engine"
| "chewing.enable_fullwidth_toggle_key" => true,
_ => false,
};
| "chewing.disable_auto_learn_phrase"
| "chewing.auto_shift_cursor"
| "chewing.candidates_per_page"
| "chewing.language_mode"
| "chewing.easy_symbol_input"
| "chewing.esc_clear_all_buffer"
| "chewing.keyboard_type"
| "chewing.auto_commit_threshold"
| "chewing.phrase_choice_rearward"
| "chewing.selection_keys"
| "chewing.character_form"
| "chewing.space_is_select_key"
| "chewing.conversion_engine"
| "chewing.enable_fullwidth_toggle_key"
);

ret as c_int
}
Expand Down Expand Up @@ -675,63 +675,63 @@ pub unsafe extern "C" fn chewing_KBStr2Num(str: *const c_char) -> c_int {
/// This function should be called with valid pointers.
#[no_mangle]
pub unsafe extern "C" fn chewing_set_ChiEngMode(ctx: *mut ChewingContext, mode: c_int) {
unsafe { chewing_config_set_int(ctx, b"chewing.language_mode\0".as_ptr().cast(), mode) };
unsafe { chewing_config_set_int(ctx, c"chewing.language_mode".as_ptr().cast(), mode) };
}

/// # Safety
///
/// This function should be called with valid pointers.
#[no_mangle]
pub unsafe extern "C" fn chewing_get_ChiEngMode(ctx: *const ChewingContext) -> c_int {
unsafe { chewing_config_get_int(ctx, b"chewing.language_mode\0".as_ptr().cast()) }
unsafe { chewing_config_get_int(ctx, c"chewing.language_mode".as_ptr().cast()) }
}

/// # Safety
///
/// This function should be called with valid pointers.
#[no_mangle]
pub unsafe extern "C" fn chewing_set_ShapeMode(ctx: *mut ChewingContext, mode: c_int) {
unsafe { chewing_config_set_int(ctx, b"chewing.character_form\0".as_ptr().cast(), mode) };
unsafe { chewing_config_set_int(ctx, c"chewing.character_form".as_ptr().cast(), mode) };
}

/// # Safety
///
/// This function should be called with valid pointers.
#[no_mangle]
pub unsafe extern "C" fn chewing_get_ShapeMode(ctx: *const ChewingContext) -> c_int {
unsafe { chewing_config_get_int(ctx, b"chewing.character_form\0".as_ptr().cast()) }
unsafe { chewing_config_get_int(ctx, c"chewing.character_form".as_ptr().cast()) }
}

/// # Safety
///
/// This function should be called with valid pointers.
#[no_mangle]
pub unsafe extern "C" fn chewing_set_candPerPage(ctx: *mut ChewingContext, n: c_int) {
unsafe { chewing_config_set_int(ctx, b"chewing.candidates_per_page\0".as_ptr().cast(), n) };
unsafe { chewing_config_set_int(ctx, c"chewing.candidates_per_page".as_ptr().cast(), n) };
}

/// # Safety
///
/// This function should be called with valid pointers.
#[no_mangle]
pub unsafe extern "C" fn chewing_get_candPerPage(ctx: *const ChewingContext) -> c_int {
unsafe { chewing_config_get_int(ctx, b"chewing.candidates_per_page\0".as_ptr().cast()) }
unsafe { chewing_config_get_int(ctx, c"chewing.candidates_per_page".as_ptr().cast()) }
}

/// # Safety
///
/// This function should be called with valid pointers.
#[no_mangle]
pub unsafe extern "C" fn chewing_set_maxChiSymbolLen(ctx: *mut ChewingContext, n: c_int) {
unsafe { chewing_config_set_int(ctx, b"chewing.auto_commit_threshold\0".as_ptr().cast(), n) };
unsafe { chewing_config_set_int(ctx, c"chewing.auto_commit_threshold".as_ptr().cast(), n) };
}

/// # Safety
///
/// This function should be called with valid pointers.
#[no_mangle]
pub unsafe extern "C" fn chewing_get_maxChiSymbolLen(ctx: *const ChewingContext) -> c_int {
unsafe { chewing_config_get_int(ctx, b"chewing.auto_commit_threshold\0".as_ptr().cast()) }
unsafe { chewing_config_get_int(ctx, c"chewing.auto_commit_threshold".as_ptr().cast()) }
}

/// # Safety
Expand Down Expand Up @@ -774,7 +774,7 @@ pub unsafe extern "C" fn chewing_set_addPhraseDirection(
unsafe {
chewing_config_set_int(
ctx,
b"chewing.user_phrase_add_direction\0".as_ptr().cast(),
c"chewing.user_phrase_add_direction".as_ptr().cast(),
direction,
)
};
Expand All @@ -785,93 +785,87 @@ pub unsafe extern "C" fn chewing_set_addPhraseDirection(
/// This function should be called with valid pointers.
#[no_mangle]
pub unsafe extern "C" fn chewing_get_addPhraseDirection(ctx: *const ChewingContext) -> c_int {
unsafe { chewing_config_get_int(ctx, b"chewing.user_phrase_add_direction\0".as_ptr().cast()) }
unsafe { chewing_config_get_int(ctx, c"chewing.user_phrase_add_direction".as_ptr().cast()) }
}

/// # Safety
///
/// This function should be called with valid pointers.
#[no_mangle]
pub unsafe extern "C" fn chewing_set_spaceAsSelection(ctx: *mut ChewingContext, mode: c_int) {
unsafe { chewing_config_set_int(ctx, b"chewing.space_is_select_key\0".as_ptr().cast(), mode) };
unsafe { chewing_config_set_int(ctx, c"chewing.space_is_select_key".as_ptr().cast(), mode) };
}

/// # Safety
///
/// This function should be called with valid pointers.
#[no_mangle]
pub unsafe extern "C" fn chewing_get_spaceAsSelection(ctx: *const ChewingContext) -> c_int {
unsafe { chewing_config_get_int(ctx, b"chewing.space_is_select_key\0".as_ptr().cast()) }
unsafe { chewing_config_get_int(ctx, c"chewing.space_is_select_key".as_ptr().cast()) }
}

/// # Safety
///
/// This function should be called with valid pointers.
#[no_mangle]
pub unsafe extern "C" fn chewing_set_escCleanAllBuf(ctx: *mut ChewingContext, mode: c_int) {
unsafe { chewing_config_set_int(ctx, b"chewing.esc_clear_all_buffer\0".as_ptr().cast(), mode) };
unsafe { chewing_config_set_int(ctx, c"chewing.esc_clear_all_buffer".as_ptr().cast(), mode) };
}

/// # Safety
///
/// This function should be called with valid pointers.
#[no_mangle]
pub unsafe extern "C" fn chewing_get_escCleanAllBuf(ctx: *const ChewingContext) -> c_int {
unsafe { chewing_config_get_int(ctx, b"chewing.esc_clear_all_buffer\0".as_ptr().cast()) }
unsafe { chewing_config_get_int(ctx, c"chewing.esc_clear_all_buffer".as_ptr().cast()) }
}

/// # Safety
///
/// This function should be called with valid pointers.
#[no_mangle]
pub unsafe extern "C" fn chewing_set_autoShiftCur(ctx: *mut ChewingContext, mode: c_int) {
unsafe { chewing_config_set_int(ctx, b"chewing.auto_shift_cursor\0".as_ptr().cast(), mode) };
unsafe { chewing_config_set_int(ctx, c"chewing.auto_shift_cursor".as_ptr().cast(), mode) };
}

/// # Safety
///
/// This function should be called with valid pointers.
#[no_mangle]
pub unsafe extern "C" fn chewing_get_autoShiftCur(ctx: *const ChewingContext) -> c_int {
unsafe { chewing_config_get_int(ctx, b"chewing.auto_shift_cursor\0".as_ptr().cast()) }
unsafe { chewing_config_get_int(ctx, c"chewing.auto_shift_cursor".as_ptr().cast()) }
}

/// # Safety
///
/// This function should be called with valid pointers.
#[no_mangle]
pub unsafe extern "C" fn chewing_set_easySymbolInput(ctx: *mut ChewingContext, mode: c_int) {
unsafe { chewing_config_set_int(ctx, b"chewing.easy_symbol_input\0".as_ptr().cast(), mode) };
unsafe { chewing_config_set_int(ctx, c"chewing.easy_symbol_input".as_ptr().cast(), mode) };
}

/// # Safety
///
/// This function should be called with valid pointers.
#[no_mangle]
pub unsafe extern "C" fn chewing_get_easySymbolInput(ctx: *const ChewingContext) -> c_int {
unsafe { chewing_config_get_int(ctx, b"chewing.easy_symbol_input\0".as_ptr().cast()) }
unsafe { chewing_config_get_int(ctx, c"chewing.easy_symbol_input".as_ptr().cast()) }
}

/// # Safety
///
/// This function should be called with valid pointers.
#[no_mangle]
pub unsafe extern "C" fn chewing_set_phraseChoiceRearward(ctx: *mut ChewingContext, mode: c_int) {
unsafe {
chewing_config_set_int(
ctx,
b"chewing.phrase_choice_rearward\0".as_ptr().cast(),
mode,
)
};
unsafe { chewing_config_set_int(ctx, c"chewing.phrase_choice_rearward".as_ptr().cast(), mode) };
}

/// # Safety
///
/// This function should be called with valid pointers.
#[no_mangle]
pub unsafe extern "C" fn chewing_get_phraseChoiceRearward(ctx: *const ChewingContext) -> c_int {
unsafe { chewing_config_get_int(ctx, b"chewing.phrase_choice_rearward\0".as_ptr().cast()) }
unsafe { chewing_config_get_int(ctx, c"chewing.phrase_choice_rearward".as_ptr().cast()) }
}

/// # Safety
Expand All @@ -882,7 +876,7 @@ pub unsafe extern "C" fn chewing_set_autoLearn(ctx: *mut ChewingContext, mode: c
unsafe {
chewing_config_set_int(
ctx,
b"chewing.disable_auto_learn_phrase\0".as_ptr().cast(),
c"chewing.disable_auto_learn_phrase".as_ptr().cast(),
mode,
)
};
Expand All @@ -893,7 +887,7 @@ pub unsafe extern "C" fn chewing_set_autoLearn(ctx: *mut ChewingContext, mode: c
/// This function should be called with valid pointers.
#[no_mangle]
pub unsafe extern "C" fn chewing_get_autoLearn(ctx: *const ChewingContext) -> c_int {
unsafe { chewing_config_get_int(ctx, b"chewing.disable_auto_learn_phrase\0".as_ptr().cast()) }
unsafe { chewing_config_get_int(ctx, c"chewing.disable_auto_learn_phrase".as_ptr().cast()) }
}

/// # Safety
Expand Down
2 changes: 1 addition & 1 deletion capi/src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl Log for ChewingLogger {
logger(
logger_data.load(Relaxed),
as_chewing_level(record.level()),
b"%s\n\0".as_ptr().cast(),
c"%s\n".as_ptr().cast(),
fmt_cstring.as_ptr(),
)
}
Expand Down
6 changes: 3 additions & 3 deletions fuzzer/src/bin/fuzzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pub fn main() -> Result<()> {
unsafe {
let ctx = chewing_new2(
syspath.as_ptr(),
b":memory:\0".as_ptr().cast(),
c":memory:".as_ptr().cast(),
None,
null_mut(),
);
Expand Down Expand Up @@ -231,7 +231,7 @@ pub fn main() -> Result<()> {
fullwidth_toggle
);
println!("# chewing.conversion_engine = {}", conversion_engine);
println!("")
println!()
}

while let Some(Ok(op)) = ops.next() {
Expand Down Expand Up @@ -445,7 +445,7 @@ pub fn main() -> Result<()> {

chewing_delete(ctx);
if gen {
println!("");
println!();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/conversion/chewing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ mod tests {
}
assert_eq!(
40,
engine.convert(&dict, &composition).nth(0).unwrap().len()
engine.convert(&dict, &composition).next().unwrap().len()
);
assert_eq!(
41,
Expand Down
10 changes: 1 addition & 9 deletions src/dictionary/trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,19 +174,11 @@ impl Trie {

/// Options and flags which can be used to configure how a trie dictionary is
/// opened.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct TrieOpenOptions {
fuzzy_search: bool,
}

impl Default for TrieOpenOptions {
fn default() -> Self {
Self {
fuzzy_search: false,
}
}
}

impl TrieOpenOptions {
pub fn new() -> TrieOpenOptions {
TrieOpenOptions::default()
Expand Down
2 changes: 1 addition & 1 deletion src/editor/zhuyin_layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ pub trait SyllableEditor: Debug {
self.key_press(key);
return ret;
}
return self.key_press(key);
self.key_press(key)
}
/// Removes the last input from the buffer.
fn remove_last(&mut self);
Expand Down
35 changes: 15 additions & 20 deletions src/editor/zhuyin_layout/pinyin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,33 +160,29 @@ impl SyllableEditor for Pinyin {
/* Hanyu empty rime
* ㄓ/ㄔ/ㄕ/ㄖ/ㄗ/ㄘ/ㄙ + -i, -i is empty rime, not ㄧ
* */
match self.variant {
PinyinVariant::HanyuPinyin => {
if matches!(
(medial, rime),
(Some(Bopomofo::I), None) | (None, Some(Bopomofo::I))
) {
match initial {
Some(Bopomofo::ZH) | Some(Bopomofo::CH) | Some(Bopomofo::SH)
| Some(Bopomofo::R) | Some(Bopomofo::Z) | Some(Bopomofo::C)
| Some(Bopomofo::S) => {
medial.take();
rime.take();
}
_ => (),
}
if self.variant == PinyinVariant::HanyuPinyin
&& matches!(
(medial, rime),
(Some(Bopomofo::I), None) | (None, Some(Bopomofo::I))
)
{
match initial {
Some(Bopomofo::ZH) | Some(Bopomofo::CH) | Some(Bopomofo::SH)
| Some(Bopomofo::R) | Some(Bopomofo::Z) | Some(Bopomofo::C) | Some(Bopomofo::S) => {
medial.take();
rime.take();
}
_ => (),

Check warning on line 175 in src/editor/zhuyin_layout/pinyin.rs

View check run for this annotation

Codecov / codecov/patch

src/editor/zhuyin_layout/pinyin.rs#L175

Added line #L175 was not covered by tests
}
_ => {}
}

/* Hanyu uan/un/u :
* ㄐ/ㄑ/ㄒ + -uan, -uan is ㄩㄢ, not ㄨㄢ
* ㄐ/ㄑ/ㄒ + -un, -un is ㄩㄣ, not ㄨㄣ
* ㄐ/ㄑ/ㄒ + -u, -u is ㄧ, not ㄨ
*/
match self.variant {
PinyinVariant::HanyuPinyin => match initial {
if self.variant == PinyinVariant::HanyuPinyin {
match initial {
Some(Bopomofo::J) | Some(Bopomofo::Q) | Some(Bopomofo::X) => {
match (medial, rime) {
(Some(Bopomofo::U), Some(Bopomofo::AN))
Expand All @@ -198,8 +194,7 @@ impl SyllableEditor for Pinyin {
};
}
_ => (),
},
_ => {}
}
}

/* THL/MPS2 s/sh/c/ch/j :
Expand Down
Loading

0 comments on commit 4084c10

Please sign in to comment.