Skip to content

Commit

Permalink
Merge pull request #10 from icanvardar/refactor/basic
Browse files Browse the repository at this point in the history
refactor: update modules according to clippy suggestions
  • Loading branch information
icanvardar authored Nov 4, 2024
2 parents fdbd8a9 + 5e753e7 commit 3a9a9aa
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 31 deletions.
39 changes: 15 additions & 24 deletions src/common/app_builder.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{error::Error, pin::Pin};
use std::error::Error;

use clap::Parser;

Expand All @@ -23,30 +23,23 @@ pub struct Args {
output: Option<String>,
}

pub trait AppBuilder {
fn build() -> Pin<Box<dyn core::future::Future<Output = Result<Arbor, Box<dyn Error>>> + Send>>
impl Arbor {
pub async fn build() -> Result<Arbor, Box<dyn Error>>
where
Self: Sync,
{
Box::pin(async move {
let args = Args::parse();

let output = if let Some(ref o) = args.output {
Some(o.as_str())
} else {
None
};

Ok(Arbor {
autocomplete: Autocomplete::build(
args.language.clone(),
args.thread_count,
args.max_suggestion,
args.backup,
output,
)
.await?,
})
let args = Args::parse();
let output = args.output.as_deref();

Ok(Arbor {
autocomplete: Autocomplete::build(
args.language.clone(),
args.thread_count,
args.max_suggestion,
args.backup,
output,
)
.await?,
})
}
}
Expand All @@ -55,8 +48,6 @@ pub struct Arbor {
pub autocomplete: Autocomplete,
}

impl AppBuilder for Arbor {}

#[cfg(test)]
mod tests {
use std::ffi::OsString;
Expand Down
6 changes: 3 additions & 3 deletions src/util/app_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ impl AppData {
}

pub fn get_language(&self) -> &str {
return self.language.as_ref();
self.language.as_ref()
}

pub fn get_thread_count(&self) -> u8 {
return self.thread_count;
self.thread_count
}

pub fn get_max_suggestion(&self) -> u8 {
return self.max_suggestion;
self.max_suggestion
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/util/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::{
io::{self, Write},
};

use crate::common::app_builder::{AppBuilder, Arbor};
use crate::common::app_builder::Arbor;

pub struct Repl {
arbor: Arbor,
Expand Down Expand Up @@ -41,7 +41,7 @@ impl Repl {
if let Event::Key(event) = event::read()? {
match event.code {
KeyCode::Char(' ') => {
if self.input.len() == 0 {
if self.input.is_empty() {
continue;
}

Expand All @@ -67,7 +67,7 @@ impl Repl {
self.selected_suggestion = 0;
}
KeyCode::Backspace => {
if self.input.len() == 0 {
if self.input.is_empty() {
continue;
}

Expand Down Expand Up @@ -112,7 +112,7 @@ impl Repl {
self.selected_suggestion += 1;
}
KeyCode::Tab => {
if self.input.len() == 0 {
if self.input.is_empty() {
continue;
}

Expand Down

0 comments on commit 3a9a9aa

Please sign in to comment.