From 9d9ecb3cc0cdb946aaf3a0af74aaa1b3e35a78f9 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Sun, 14 Apr 2024 10:50:30 -0500 Subject: [PATCH] rustfmt things --- src/rust/lib.rs | 1 - src/rust/obs.rs | 47 ++++++++++++++++++-------------- src/rust/service_item_model.rs | 12 ++++----- src/rust/slide_model.rs | 49 ++++++++++++++++++++++------------ src/rust/songs/song_lyrics.rs | 4 +-- src/rust/ytdl.rs | 22 +++++++-------- 6 files changed, 75 insertions(+), 60 deletions(-) diff --git a/src/rust/lib.rs b/src/rust/lib.rs index d04bc21..9a64663 100644 --- a/src/rust/lib.rs +++ b/src/rust/lib.rs @@ -16,4 +16,3 @@ pub mod utils; pub mod video_model; pub mod ytdl; // mod video_thumbnail; - diff --git a/src/rust/obs.rs b/src/rust/obs.rs index 433568a..9f680ab 100644 --- a/src/rust/obs.rs +++ b/src/rust/obs.rs @@ -1,11 +1,11 @@ use core::fmt; -use std::{error::Error, pin::Pin}; -use std::thread::sleep; -use std::time::Duration; use cxx_qt::CxxQtType; -use cxx_qt_lib::{QStringList, QString}; +use cxx_qt_lib::{QString, QStringList}; use obws::responses::scenes::Scenes; use obws::Client; +use std::thread::sleep; +use std::time::Duration; +use std::{error::Error, pin::Pin}; use tracing::{debug, error}; use crate::obs::obs_model::QList_QString; @@ -13,7 +13,7 @@ use crate::obs::obs_model::QList_QString; pub struct Obs { scenes: Scenes, client: Option, - current_program_scene: Option + current_program_scene: Option, } impl fmt::Debug for Obs { @@ -30,7 +30,7 @@ impl Clone for Obs { Self { scenes: self.scenes.clone(), client: Some(make_client()), - current_program_scene: self.current_program_scene.clone() + current_program_scene: self.current_program_scene.clone(), } } } @@ -40,7 +40,7 @@ impl Default for Obs { Self { scenes: Scenes::default(), client: None, - current_program_scene: None + current_program_scene: None, } } } @@ -51,12 +51,13 @@ impl Obs { Client::connect("localhost", 4455, Some("")).await?; let scenes_object = client.scenes(); let scene_list = scenes_object.list().await?; - let current_program_scene = scenes_object.current_program_scene().await?; + let current_program_scene = + scenes_object.current_program_scene().await?; debug!(?scene_list); Ok(Self { scenes: scene_list, client: Some(client), - current_program_scene: Some(current_program_scene) + current_program_scene: Some(current_program_scene), }) } @@ -84,12 +85,17 @@ impl Obs { let client = make_client(); let runtime = tokio::runtime::Runtime::new()?; - let handle = runtime.spawn(async move { + let handle = runtime.spawn(async move { debug!("in spawn: before setting"); - let res = client.scenes().set_current_program_scene(&scene).await; + let res = client + .scenes() + .set_current_program_scene(&scene) + .await; match res { - Ok(o) => debug!("in spawn: after setting: success"), - Err(e) => error!(?e, "in spawn: after setting") + Ok(o) => { + debug!("in spawn: after setting: success") + } + Err(e) => error!(?e, "in spawn: after setting"), } }); @@ -151,13 +157,11 @@ pub struct ObsModelRust { port: QString, connected: bool, obs: Option, - current_program_scene: QString + current_program_scene: QString, } impl obs_model::ObsModel { - pub fn update_scenes( - mut self: Pin<&mut Self>, - ) -> QStringList { + pub fn update_scenes(mut self: Pin<&mut Self>) -> QStringList { debug!("updating scenes"); let mut scenes_list = QList_QString::default(); if let Some(obs) = &self.as_mut().rust_mut().obs { @@ -184,7 +188,8 @@ impl obs_model::ObsModel { Ok(o) => { if let Some(scene) = &o.current_program_scene { let scene = QString::from(scene); - self.as_mut().set_current_program_scene(scene); + self.as_mut() + .set_current_program_scene(scene); } self.as_mut().set_connected(true); self.as_mut().rust_mut().obs = Some(o); @@ -219,14 +224,16 @@ impl obs_model::ObsModel { #[cfg(test)] mod test { use super::*; - + #[test] pub fn test_obs_setting_scene() { let runtime = tokio::runtime::Runtime::new().unwrap(); let future = Client::connect("localhost", 4455, Some("")); let client = runtime.block_on(future).unwrap(); let scene = String::from("me"); - let res = runtime.block_on(client.scenes().set_current_program_scene(&scene)); + let res = runtime.block_on( + client.scenes().set_current_program_scene(&scene), + ); debug_assert!(res.is_ok()); } } diff --git a/src/rust/service_item_model.rs b/src/rust/service_item_model.rs index 8c968de..c45849e 100644 --- a/src/rust/service_item_model.rs +++ b/src/rust/service_item_model.rs @@ -285,24 +285,22 @@ use cxx_qt_lib::{ QByteArray, QModelIndex, QString, QStringList, QUrl, QVariant, }; use dirs; -use serde::{Deserialize, Serialize}; -use serde_json::{json, Deserializer, Map, Serializer, Value}; -use std::ffi::{OsStr, OsString}; -use std::io::{self, Read, Write}; +use serde_json::{json, Value}; +use std::io::{Read, Write}; use std::iter; use std::path::{Path, PathBuf}; use std::pin::Pin; -use std::str; use std::{fs, println}; use tar::{Archive, Builder}; -use tracing::{debug, debug_span, error, info, instrument}; +use tracing::{debug, error}; use zstd::{Decoder, Encoder}; - use self::service_item_model::{ QHash_i32_QByteArray, QMap_QString_QVariant, QVector_i32, ServiceRoles, }; +use super::service_item_model::service_item_model::ServiceItemModel; + #[derive(Clone, Debug)] pub struct ServiceItem { name: QString, diff --git a/src/rust/slide_model.rs b/src/rust/slide_model.rs index 9499967..d601897 100644 --- a/src/rust/slide_model.rs +++ b/src/rust/slide_model.rs @@ -287,7 +287,6 @@ pub struct SlideModelRust { count: i32, } - impl Default for SlideModelRust { fn default() -> Self { let obs = @@ -319,7 +318,10 @@ impl slide_model::SlideModel { .append(self.get_role(SlideRoles::VideoThumbnail)); let thread = self.qt_thread(); - let model_index = self.as_ref().index(index, 0, &QModelIndex::default()).clone(); + let model_index = self + .as_ref() + .index(index, 0, &QModelIndex::default()) + .clone(); if let Some(slide) = self.as_mut().rust_mut().slides.get_mut(index as usize) { @@ -327,26 +329,39 @@ impl slide_model::SlideModel { let path = PathBuf::from(slide.video_background.to_string()); let screenshot = ffmpeg::bg_path_from_video(&path); - let screenshot_string = QString::from( - screenshot.to_str().unwrap() - ).insert(0, &QString::from("file://")).to_owned(); + let screenshot_string = + QString::from(screenshot.to_str().unwrap()) + .insert(0, &QString::from("file://")) + .to_owned(); slide.video_thumbnail = screenshot_string; std::thread::spawn(move || { - let result = ffmpeg::bg_from_video(&path, &screenshot); + let result = + ffmpeg::bg_from_video(&path, &screenshot); match result { - Ok(_o) => debug!("Success making video background!"), - Err(error) => error!(?error, "Error making video background") + Ok(_o) => { + debug!("Success making video background!") + } + Err(error) => error!( + ?error, + "Error making video background" + ), }; - let result = thread.queue(move |mut slide_model| - slide_model.as_mut().data_changed( - &model_index, - &model_index, - &vector_roles, - ) - ); + let result = + thread.queue(move |mut slide_model| { + slide_model.as_mut().data_changed( + &model_index, + &model_index, + &vector_roles, + ) + }); match result { - Ok(o) => debug!("Success in creating qt_thread"), - Err(error) => error!(?error, "Error in creating qt_thread") + Ok(o) => { + debug!("Success in creating qt_thread") + } + Err(error) => error!( + ?error, + "Error in creating qt_thread" + ), } }); } diff --git a/src/rust/songs/song_lyrics.rs b/src/rust/songs/song_lyrics.rs index 0531f27..a2e38f9 100644 --- a/src/rust/songs/song_lyrics.rs +++ b/src/rust/songs/song_lyrics.rs @@ -54,7 +54,6 @@ impl SongBuilder { artist_names: self.artist_names.unwrap_or_default(), } } - } pub fn search_song(s: &str) -> Result, Error> { @@ -103,7 +102,8 @@ mod tests { .init(); let song = "Perfect"; - let res = search_song(song).unwrap().into_iter().next().unwrap(); + let res = + search_song(song).unwrap().into_iter().next().unwrap(); let song = Song { title: String::from("Perfect"), lyrics: String::from(""), diff --git a/src/rust/ytdl.rs b/src/rust/ytdl.rs index 14a5b1c..cd6c2cc 100644 --- a/src/rust/ytdl.rs +++ b/src/rust/ytdl.rs @@ -27,8 +27,8 @@ mod ytdl { use cxx_qt::{CxxQtType, Threading}; use cxx_qt_lib::{QString, QUrl}; use dirs; -use tracing::debug; use std::{fs, pin::Pin}; +use tracing::debug; use youtube_dl::YoutubeDl; #[derive(Clone, Default)] @@ -41,10 +41,7 @@ pub struct YtdlRust { } impl ytdl::Ytdl { - pub fn get_video( - mut self: Pin<&mut Self>, - url: QUrl, - ) -> bool { + pub fn get_video(mut self: Pin<&mut Self>, url: QUrl) -> bool { if !url.is_valid() { false } else { @@ -58,8 +55,7 @@ impl ytdl::Ytdl { debug!(?data_dir); self.as_mut().set_loading(true); let thread = self.qt_thread(); - let runtime = - tokio::runtime::Runtime::new().unwrap(); + let runtime = tokio::runtime::Runtime::new().unwrap(); runtime.spawn(async move { let url = url.to_string(); let output_dirs = data_dir.to_str().unwrap(); @@ -71,9 +67,11 @@ impl ytdl::Ytdl { .download(true) .run() .unwrap(); - let output = - ytdl.into_single_video().unwrap(); - debug!(output.title, output.thumbnail, output.url); + let output = ytdl.into_single_video().unwrap(); + debug!( + output.title, + output.thumbnail, output.url + ); let title = QString::from(&output.title); let thumbnail = QUrl::from( &output.thumbnail.unwrap_or_default(), @@ -82,9 +80,7 @@ impl ytdl::Ytdl { file.push_str("/"); file.push_str(&output.title); file.push_str("."); - file.push_str( - &output.ext.unwrap_or_default(), - ); + file.push_str(&output.ext.unwrap_or_default()); debug!(file); thread.queue(move |mut qobject_ytdl| {