From 0a3e6f309679dd867d276a992632a211ba02ef4d Mon Sep 17 00:00:00 2001 From: Damien Murphy Date: Sat, 13 Jul 2024 09:38:56 -0700 Subject: [PATCH] fix Clippy, Format, Documentation, Minimal-Version --- examples/advanced_stream.rs | 2 +- src/transcription/live.rs | 31 ++++++++++++------------ src/transcription/prerecorded/options.rs | 15 ++++++------ 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/examples/advanced_stream.rs b/examples/advanced_stream.rs index d0fc05a8..ff26df21 100644 --- a/examples/advanced_stream.rs +++ b/examples/advanced_stream.rs @@ -16,7 +16,7 @@ async fn main() -> Result<(), DeepgramError> { .smart_format(true) .language(Language::en_US) .build(); - + let mut results = dg .transcription() .stream_request_with_options(Some(&options)) diff --git a/src/transcription/live.rs b/src/transcription/live.rs index 49b2d0ad..18ebaa5c 100644 --- a/src/transcription/live.rs +++ b/src/transcription/live.rs @@ -13,8 +13,8 @@ use std::path::Path; use std::pin::Pin; use std::task::{Context, Poll}; use std::time::Duration; -use serde_urlencoded; use serde_json::Value; +use serde_urlencoded; use bytes::{Bytes, BytesMut}; use futures::channel::mpsc::{self, Receiver}; @@ -85,20 +85,19 @@ pub enum StreamResponse { UtteranceEndResponse { r#type: String, channel: Vec, - last_word_end: f64 + last_word_end: f64, }, SpeechStartedResponse { r#type: String, channel: Vec, - timestamp: f64 + timestamp: f64, }, TerminalResponse { request_id: String, created: String, duration: f64, channels: u32, - }, - Other(Value), // Log unhandled messages if any + } } #[pin_project] @@ -110,7 +109,7 @@ struct FileChunker { } impl Transcription<'_> { - pub fn stream_request<'a, E, S>(&'a self) -> StreamRequestBuilder<'a, S, E> + pub fn stream_request(&self) -> StreamRequestBuilder<'_, S, E> where S: Stream>, { @@ -119,14 +118,14 @@ impl Transcription<'_> { pub fn stream_request_with_options<'a, E, S>( &'a self, - options: Option<&'a Options> + options: Option<&'a Options>, ) -> StreamRequestBuilder<'a, S, E> where S: Stream>, { StreamRequestBuilder { config: self.0, - options: options, + options, source: None, encoding: None, sample_rate: None, @@ -226,7 +225,7 @@ where self } - + pub fn utterance_end_ms(mut self, utterance_end_ms: u16) -> Self { self.utterance_end_ms = Some(utterance_end_ms); @@ -238,19 +237,18 @@ where self } - + pub fn no_delay(mut self, no_delay: bool) -> Self { self.no_delay = Some(no_delay); self } - + pub fn vad_events(mut self, vad_events: bool) -> Self { self.vad_events = Some(vad_events); self } - } impl<'a> StreamRequestBuilder<'a, Receiver>, DeepgramError> { @@ -280,7 +278,7 @@ impl<'a> StreamRequestBuilder<'a, Receiver>, DeepgramError> { fn options_to_query_string(options: &Options) -> String { let serialized_options = SerializableOptions::from(options); - serde_urlencoded::to_string(&serialized_options).unwrap_or_default() + serde_urlencoded::to_string(serialized_options).unwrap_or_default() } impl StreamRequestBuilder<'_, S, E> @@ -297,16 +295,17 @@ where // Add standard pre-recorded options if let Some(options) = &self.options { let query_string = options_to_query_string(options); - let query_pairs: Vec<(Cow, Cow)> = query_string.split('&') + let query_pairs: Vec<(Cow, Cow)> = query_string + .split('&') .map(|s| { let mut split = s.splitn(2, '='); ( Cow::from(split.next().unwrap_or_default()), - Cow::from(split.next().unwrap_or_default()) + Cow::from(split.next().unwrap_or_default()), ) }) .collect(); - + for (key, value) in query_pairs { pairs.append_pair(&key, &value); } diff --git a/src/transcription/prerecorded/options.rs b/src/transcription/prerecorded/options.rs index f5de44ad..8819cab7 100644 --- a/src/transcription/prerecorded/options.rs +++ b/src/transcription/prerecorded/options.rs @@ -30,7 +30,7 @@ pub struct Options { query_params: Vec<(String, String)>, encoding: Option, smart_format: Option, - filler_words: Option + filler_words: Option, } /// Used as a parameter for [`OptionsBuilder::model`] and [`OptionsBuilder::multichannel_with_models`]. @@ -427,8 +427,7 @@ pub enum Utterances { /// Enabled Enabled { /// utt_split - /// [docs]: https://developers.deepgram.com/docs/utterance-split - utt_split: Option + utt_split: Option, }, } @@ -444,7 +443,7 @@ pub enum Multichannel { /// Enabled Enabled { /// models - models: Option> + models: Option>, }, } @@ -493,7 +492,7 @@ impl OptionsBuilder { query_params: Vec::new(), encoding: None, smart_format: None, - filler_words: None + filler_words: None, }) } @@ -1287,8 +1286,8 @@ impl OptionsBuilder { self } - /// Encoding is required when raw, headerless audio packets are sent to the - /// streaming service. If containerized audio packets are sent to the + /// Encoding is required when raw, headerless audio packets are sent to the + /// streaming service. If containerized audio packets are sent to the /// streaming service, this feature should not be used. /// /// See the [Deepgram Encoding feature docs][docs] for more info. @@ -1403,7 +1402,7 @@ impl Serialize for SerializableOptions<'_> { query_params, encoding, smart_format, - filler_words + filler_words, } = self.0; match multichannel {