diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0faa6dd4..d7c4c6ab 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ on: types: [checks_requested] env: - RUST_VERSION: "1.77" + RUST_VERSION: "1.83" CMAKE_GENERATOR: Ninja jobs: diff --git a/Cargo.toml b/Cargo.toml index 8dc4bf63..0d0a191e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 = [ diff --git a/README.md b/README.md index d1f56a7a..6e4b56dc 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,7 @@ be built. - cmake >= 3.21.0 + Toolchain / IDE: - clang >= 3.2 OR gcc >= 4.6.3 - - Rust >= 1.77 + - Rust >= 1.83 - Build Tools for Visual Studio 2022 for MSVC build - Vcpkg for MSVC build + Documentation tools: @@ -191,7 +191,7 @@ To ensure libchewing can be built on various Linux distributions, we use the minimum rust version available from major distributions' next release branch. Data source: https://repology.org/project/rust/versions -* Current MSRV: 1.77.0 (Debian unstable) +* Current MSRV: 1.83.0 (Debian unstable) ## Usage diff --git a/capi/Cargo.toml b/capi/Cargo.toml index c11510db..c518e1b3 100644 --- a/capi/Cargo.toml +++ b/capi/Cargo.toml @@ -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] diff --git a/capi/src/io.rs b/capi/src/io.rs index 1c10ba92..b1c6be48 100644 --- a/capi/src/io.rs +++ b/capi/src/io.rs @@ -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 } @@ -675,7 +675,7 @@ 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 @@ -683,7 +683,7 @@ pub unsafe extern "C" fn chewing_set_ChiEngMode(ctx: *mut ChewingContext, mode: /// 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 @@ -691,7 +691,7 @@ pub unsafe extern "C" fn chewing_get_ChiEngMode(ctx: *const ChewingContext) -> c /// 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 @@ -699,7 +699,7 @@ pub unsafe extern "C" fn chewing_set_ShapeMode(ctx: *mut ChewingContext, mode: c /// 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 @@ -707,7 +707,7 @@ pub unsafe extern "C" fn chewing_get_ShapeMode(ctx: *const ChewingContext) -> c_ /// 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 @@ -715,7 +715,7 @@ pub unsafe extern "C" fn chewing_set_candPerPage(ctx: *mut ChewingContext, n: c_ /// 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 @@ -723,7 +723,7 @@ pub unsafe extern "C" fn chewing_get_candPerPage(ctx: *const ChewingContext) -> /// 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 @@ -731,7 +731,7 @@ pub unsafe extern "C" fn chewing_set_maxChiSymbolLen(ctx: *mut ChewingContext, n /// 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 @@ -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, ) }; @@ -785,7 +785,7 @@ 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 @@ -793,7 +793,7 @@ pub unsafe extern "C" fn chewing_get_addPhraseDirection(ctx: *const ChewingConte /// 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 @@ -801,7 +801,7 @@ pub unsafe extern "C" fn chewing_set_spaceAsSelection(ctx: *mut ChewingContext, /// 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 @@ -809,7 +809,7 @@ pub unsafe extern "C" fn chewing_get_spaceAsSelection(ctx: *const ChewingContext /// 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 @@ -817,7 +817,7 @@ pub unsafe extern "C" fn chewing_set_escCleanAllBuf(ctx: *mut ChewingContext, mo /// 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 @@ -825,7 +825,7 @@ pub unsafe extern "C" fn chewing_get_escCleanAllBuf(ctx: *const ChewingContext) /// 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 @@ -833,7 +833,7 @@ pub unsafe extern "C" fn chewing_set_autoShiftCur(ctx: *mut ChewingContext, mode /// 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 @@ -841,7 +841,7 @@ pub unsafe extern "C" fn chewing_get_autoShiftCur(ctx: *const ChewingContext) -> /// 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 @@ -849,7 +849,7 @@ pub unsafe extern "C" fn chewing_set_easySymbolInput(ctx: *mut ChewingContext, m /// 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 @@ -857,13 +857,7 @@ pub unsafe extern "C" fn chewing_get_easySymbolInput(ctx: *const ChewingContext) /// 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 @@ -871,7 +865,7 @@ pub unsafe extern "C" fn chewing_set_phraseChoiceRearward(ctx: *mut ChewingConte /// 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 @@ -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, ) }; @@ -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 diff --git a/capi/src/logger.rs b/capi/src/logger.rs index 84a62060..442d82f1 100644 --- a/capi/src/logger.rs +++ b/capi/src/logger.rs @@ -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(), ) } diff --git a/fuzzer/src/bin/fuzzer.rs b/fuzzer/src/bin/fuzzer.rs index 2b874599..45400f6a 100644 --- a/fuzzer/src/bin/fuzzer.rs +++ b/fuzzer/src/bin/fuzzer.rs @@ -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(), ); @@ -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() { @@ -445,7 +445,7 @@ pub fn main() -> Result<()> { chewing_delete(ctx); if gen { - println!(""); + println!(); } } diff --git a/src/conversion/chewing.rs b/src/conversion/chewing.rs index e687006d..3cac6512 100644 --- a/src/conversion/chewing.rs +++ b/src/conversion/chewing.rs @@ -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, diff --git a/src/dictionary/trie.rs b/src/dictionary/trie.rs index cb3bc570..52e7cf7d 100644 --- a/src/dictionary/trie.rs +++ b/src/dictionary/trie.rs @@ -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() diff --git a/src/editor/zhuyin_layout/mod.rs b/src/editor/zhuyin_layout/mod.rs index 2a41b00b..b820b883 100644 --- a/src/editor/zhuyin_layout/mod.rs +++ b/src/editor/zhuyin_layout/mod.rs @@ -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); diff --git a/src/editor/zhuyin_layout/pinyin.rs b/src/editor/zhuyin_layout/pinyin.rs index 90863764..c1f680c7 100644 --- a/src/editor/zhuyin_layout/pinyin.rs +++ b/src/editor/zhuyin_layout/pinyin.rs @@ -160,24 +160,20 @@ 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(); } + _ => (), } - _ => {} } /* Hanyu uan/un/u : @@ -185,8 +181,8 @@ impl SyllableEditor for Pinyin { * ㄐ/ㄑ/ㄒ + -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)) @@ -198,8 +194,7 @@ impl SyllableEditor for Pinyin { }; } _ => (), - }, - _ => {} + } } /* THL/MPS2 s/sh/c/ch/j : diff --git a/src/path.rs b/src/path.rs index dc67c39b..112229d1 100644 --- a/src/path.rs +++ b/src/path.rs @@ -65,17 +65,15 @@ pub(crate) fn find_extra_dat_by_path(search_path: &str) -> Vec { info!("Search dictionary files in {}", prefix.display()); if let Ok(read_dir) = prefix.read_dir() { let mut files = vec![]; - for entry in read_dir { - if let Ok(entry) = entry { - let path = entry.path(); - let is_dat = path - .extension() - .and_then(OsStr::to_str) - .map_or(false, |ext| ext == "dat"); - if path.is_file() && is_dat { - info!("Found {}", path.display()); - files.push(path); - } + for entry in read_dir.flatten() { + let path = entry.path(); + let is_dat = path + .extension() + .and_then(OsStr::to_str) + .map_or(false, |ext| ext == "dat"); + if path.is_file() && is_dat { + info!("Found {}", path.display()); + files.push(path); } } files.sort(); diff --git a/src/zhuyin/syllable.rs b/src/zhuyin/syllable.rs index aa0b8789..10bf98c9 100644 --- a/src/zhuyin/syllable.rs +++ b/src/zhuyin/syllable.rs @@ -154,7 +154,7 @@ impl Syllable { }; let self_prefix = self.to_u16() >> mask; let other_prefix = other.to_u16() >> mask; - return self_prefix == other_prefix; + self_prefix == other_prefix } /// Returns the `Syllable` encoded in a u16 integer. ///