summaryrefslogtreecommitdiff
path: root/src/systems
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-03-20 22:21:56 +0800
committer魏曹先生 <1992414357@qq.com>2026-03-20 22:21:56 +0800
commitab6be7968b25afb57fc428695693484ad8576718 (patch)
treee4af27964f195a18a678844dbe71c0aaa182b5dc /src/systems
parent6b22f7b7694fce530f84ba94c65c057450cca626 (diff)
Refactor code to use modern Rust idioms and fix clippy lints
Diffstat (limited to 'src/systems')
-rw-r--r--src/systems/cmd/macros.rs4
-rw-r--r--src/systems/cmd/processer.rs10
-rw-r--r--src/systems/helpdoc/helpdoc_viewer.rs28
-rw-r--r--src/systems/render/renderer.rs2
4 files changed, 21 insertions, 23 deletions
diff --git a/src/systems/cmd/macros.rs b/src/systems/cmd/macros.rs
index 9e2446b..0502a26 100644
--- a/src/systems/cmd/macros.rs
+++ b/src/systems/cmd/macros.rs
@@ -149,7 +149,7 @@ macro_rules! command_template {
input: In,
collect: Collect,
) -> Result<
- crate::systems::cmd::cmd_system::AnyOutput,
+ $crate::systems::cmd::cmd_system::AnyOutput,
$crate::systems::cmd::errors::CmdExecuteError,
> {
exec(input, collect).await
@@ -188,7 +188,7 @@ macro_rules! cmd_output {
macro_rules! early_cmd_output {
($t:ty => $v:expr) => {{
let checked_value: $t = $v;
- Err(crate::systems::cmd::errors::CmdPrepareError::EarlyOutput((
+ Err($crate::systems::cmd::errors::CmdPrepareError::EarlyOutput((
Box::new(checked_value) as Box<dyn std::any::Any + Send + 'static>,
std::any::TypeId::of::<$t>(),
)))
diff --git a/src/systems/cmd/processer.rs b/src/systems/cmd/processer.rs
index aa494bb..2b66eef 100644
--- a/src/systems/cmd/processer.rs
+++ b/src/systems/cmd/processer.rs
@@ -8,7 +8,7 @@ use crate::systems::cmd::errors::CmdProcessError;
use crate::systems::render::renderer::JVRenderResult;
pub async fn jv_cmd_process(
- args: &Vec<String>,
+ args: &[String],
ctx: JVCommandContext,
renderer_override: String,
) -> Result<JVRenderResult, CmdProcessError> {
@@ -22,7 +22,7 @@ pub async fn jv_cmd_process(
}
async fn process(
- args: &Vec<String>,
+ args: &[String],
ctx: JVCommandContext,
renderer_override: String,
) -> Result<JVRenderResult, CmdProcessError> {
@@ -48,7 +48,7 @@ async fn process(
0 => {
// No matching node found
error!("{}", t!("verbose.cmd_match_no_node"));
- return Err(CmdProcessError::NoMatchingCommand);
+ Err(CmdProcessError::NoMatchingCommand)
}
1 => {
let matched_prefix = matching_nodes[0];
@@ -60,7 +60,7 @@ async fn process(
);
let prefix_len = matched_prefix.split_whitespace().count();
- let trimmed_args: Vec<String> = args.into_iter().cloned().skip(prefix_len).collect();
+ let trimmed_args: Vec<String> = args.iter().skip(prefix_len).cloned().collect();
return jv_cmd_process_node(matched_prefix, trimmed_args, ctx, renderer_override).await;
}
_ => {
@@ -84,7 +84,7 @@ async fn process(
);
let prefix_len = matched_prefix.split_whitespace().count();
- let trimmed_args: Vec<String> = args.into_iter().cloned().skip(prefix_len).collect();
+ let trimmed_args: Vec<String> = args.iter().skip(prefix_len).cloned().collect();
return jv_cmd_process_node(matched_prefix, trimmed_args, ctx, renderer_override).await;
}
}
diff --git a/src/systems/helpdoc/helpdoc_viewer.rs b/src/systems/helpdoc/helpdoc_viewer.rs
index 560b827..db7f2c6 100644
--- a/src/systems/helpdoc/helpdoc_viewer.rs
+++ b/src/systems/helpdoc/helpdoc_viewer.rs
@@ -251,10 +251,10 @@ impl HelpdocViewer {
while !should_exit {
self.draw()?;
- if event::poll(std::time::Duration::from_millis(100))? {
- if let Event::Key(key) = event::read()? {
- should_exit = self.handle_key(key);
- }
+ if event::poll(std::time::Duration::from_millis(100))?
+ && let Event::Key(key) = event::read()?
+ {
+ should_exit = self.handle_key(key);
}
}
@@ -330,6 +330,7 @@ impl HelpdocViewer {
}
/// Recursively draw tree node
+ #[allow(clippy::too_many_arguments)]
fn draw_tree_node(
&self,
node: &DocTreeNode,
@@ -442,8 +443,8 @@ impl HelpdocViewer {
}
// Display scroll position indicator
- if content_lines.len() > height as usize && content_lines.len() > 0 {
- let scroll_percent = if content_lines.len() > 0 {
+ if content_lines.len() > height as usize && !content_lines.is_empty() {
+ let scroll_percent = if !content_lines.is_empty() {
(scroll_pos * 100) / content_lines.len()
} else {
0
@@ -580,16 +581,13 @@ impl HelpdocViewer {
/// Select current item
fn select_item(&mut self) {
- match self.focus {
- FocusArea::Tree => {
- // Update current document to the one selected in tree view
- if let Some(doc) = self.doc_tree.flat_docs.get(self.tree_selection_index) {
- self.current_doc = doc.clone();
- }
- // Switch focus to content area
- self.focus = FocusArea::Content;
+ if self.focus == FocusArea::Tree {
+ // Update current document to the one selected in tree view
+ if let Some(doc) = self.doc_tree.flat_docs.get(self.tree_selection_index) {
+ self.current_doc = doc.clone();
}
- _ => {}
+ // Switch focus to content area
+ self.focus = FocusArea::Content;
}
}
diff --git a/src/systems/render/renderer.rs b/src/systems/render/renderer.rs
index 13de8c6..1a4029f 100644
--- a/src/systems/render/renderer.rs
+++ b/src/systems/render/renderer.rs
@@ -20,7 +20,7 @@ pub struct JVRenderResult {
impl Display for JVRenderResult {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
- write!(f, "{}\n", self.render_text.trim())
+ writeln!(f, "{}", self.render_text.trim())
}
}