Skip to content

Commit 18e689a

Browse files
fix: apply clippy suggested fixes (#2165)
- whisper-local: use struct initialization instead of field reassignment - analytics: rename AnalyticsPayload::new to builder (new_ret_no_self) - vvad: add custom VadError type instead of Result<_, ()> - buffer: add type aliases for complex types (TextTransformation, MdTransformation) - llama: add #[allow(clippy::too_many_arguments)] for process_generation Co-Authored-By: unknown <> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent 9549214 commit 18e689a

File tree

9 files changed

+25
-13
lines changed

9 files changed

+25
-13
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/analytics/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ pub struct AnalyticsPayloadBuilder {
135135
}
136136

137137
impl AnalyticsPayload {
138-
pub fn new(event: impl Into<String>) -> AnalyticsPayloadBuilder {
138+
pub fn builder(event: impl Into<String>) -> AnalyticsPayloadBuilder {
139139
AnalyticsPayloadBuilder {
140140
event: Some(event.into()),
141141
props: HashMap::new(),
@@ -169,7 +169,7 @@ mod tests {
169169
#[tokio::test]
170170
async fn test_analytics() {
171171
let client = AnalyticsClient::new(Some(""));
172-
let payload = AnalyticsPayload::new("test_event")
172+
let payload = AnalyticsPayload::builder("test_event")
173173
.with("key1", "value1")
174174
.with("key2", 2)
175175
.build();

crates/buffer/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ pub enum Error {
1010
HTMLParseError(String),
1111
}
1212

13+
type TextTransformation = Box<dyn Fn(&mut String)>;
14+
type MdTransformation = Box<dyn Fn(&mut markdown::mdast::Node)>;
15+
1316
pub fn opinionated_md_to_html(text: impl AsRef<str>) -> Result<String, Error> {
1417
let md = md_to_md(text)?;
1518
let md_with_mentions = transform_mentions_in_markdown(&md);
@@ -23,7 +26,7 @@ pub fn opinionated_md_to_md(text: impl AsRef<str>) -> Result<String, Error> {
2326
fn md_to_md(text: impl AsRef<str>) -> Result<String, Error> {
2427
let mut text = text.as_ref().to_string();
2528

26-
let txt_transformations: Vec<Box<dyn Fn(&mut String)>> = vec![Box::new(remove_char_repeat)];
29+
let txt_transformations: Vec<TextTransformation> = vec![Box::new(remove_char_repeat)];
2730

2831
for t in txt_transformations {
2932
t(&mut text);
@@ -32,7 +35,7 @@ fn md_to_md(text: impl AsRef<str>) -> Result<String, Error> {
3235
let mut ast = markdown::to_mdast(text.as_ref(), &markdown::ParseOptions::default())
3336
.map_err(|e| Error::MarkdownParseError(e.to_string()))?;
3437

35-
let md_transformations: Vec<Box<dyn Fn(&mut markdown::mdast::Node)>> = vec![
38+
let md_transformations: Vec<MdTransformation> = vec![
3639
Box::new(remove_thematic_break),
3740
Box::new(remove_empty_headings),
3841
Box::new(|node| {

crates/llama/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ impl Llama {
245245
Ok((ctx, batch, last_index, progress_data_ptr, max_output_tokens))
246246
}
247247

248+
#[allow(clippy::too_many_arguments)]
248249
fn process_generation<'a>(
249250
model: &LlamaModel,
250251
mut ctx: llama_cpp_2::context::LlamaContext<'a>,

crates/vvad/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ edition = "2021"
55

66
[dependencies]
77
earshot = { workspace = true }
8+
thiserror = { workspace = true }

crates/vvad/src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
mod earshot_impl {
22
use earshot::VoiceActivityProfile;
33

4+
#[derive(Debug, thiserror::Error)]
5+
#[error("voice activity detection failed")]
6+
pub struct VadError;
7+
48
pub struct VoiceActivityDetector {
59
inner: earshot::VoiceActivityDetector,
610
}
@@ -12,8 +16,8 @@ mod earshot_impl {
1216
}
1317
}
1418

15-
pub fn predict_16khz(&mut self, samples: &[i16]) -> Result<bool, ()> {
16-
self.inner.predict_16khz(samples).map_err(|_| ())
19+
pub fn predict_16khz(&mut self, samples: &[i16]) -> Result<bool, VadError> {
20+
self.inner.predict_16khz(samples).map_err(|_| VadError)
1721
}
1822
}
1923

crates/whisper-local/src/model/actual.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ impl WhisperBuilder {
3737
unsafe { Self::suppress_log() };
3838

3939
let context_param = {
40-
let mut p = WhisperContextParameters::default();
41-
p.gpu_device = 0;
42-
p.use_gpu = true;
43-
p.flash_attn = false; // crash on macos
40+
let mut p = WhisperContextParameters {
41+
gpu_device: 0,
42+
use_gpu: true,
43+
flash_attn: false, // crash on macos
44+
..Default::default()
45+
};
4446
p.dtw_parameters.mode = whisper_rs::DtwMode::None;
4547
p
4648
};

plugins/analytics/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ mod test {
7070
async fn test_analytics() {
7171
let app = create_app(tauri::test::mock_builder());
7272
let result = app
73-
.event(hypr_analytics::AnalyticsPayload::new("test_event").build())
73+
.event(hypr_analytics::AnalyticsPayload::builder("test_event").build())
7474
.await;
7575
assert!(result.is_ok());
7676

plugins/windows/src/ext.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl AppWindow {
7979
if self.label() == "main" {
8080
use tauri_plugin_analytics::{AnalyticsPayload, AnalyticsPluginExt};
8181

82-
let e = AnalyticsPayload::new("show_main_window").build();
82+
let e = AnalyticsPayload::builder("show_main_window").build();
8383

8484
let app_clone = app.clone();
8585
tauri::async_runtime::spawn(async move {
@@ -173,7 +173,7 @@ impl WindowsPluginExt<tauri::Wry> for AppHandle<tauri::Wry> {
173173
{
174174
use tauri_plugin_analytics::{AnalyticsPayload, AnalyticsPluginExt};
175175

176-
let e = AnalyticsPayload::new(event_name)
176+
let e = AnalyticsPayload::builder(event_name)
177177
.with("user_id", user_id)
178178
.with("session_id", session_id)
179179
.build();

0 commit comments

Comments
 (0)