Skip to content

Commit

Permalink
Merge pull request #664 from chewing/refactor-msrv-1_83
Browse files Browse the repository at this point in the history
refactor!: bump MSRV to 1.83 and fix clippy warnings
  • Loading branch information
kanru authored Dec 12, 2024
2 parents 9d7ab41 + f0b07c2 commit 786b0ff
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 97 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
types: [checks_requested]

env:
RUST_VERSION: "1.77"
RUST_VERSION: "1.83"
CMAKE_GENERATOR: Ninja

jobs:
Expand Down
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
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
Loading

0 comments on commit 786b0ff

Please sign in to comment.