Skip to content

Commit b9e38e5

Browse files
author
Deren Vural
committed
trunk formatting
Signed-off-by: Deren Vural <[email protected]>
1 parent 763bb19 commit b9e38e5

File tree

4 files changed

+40
-33
lines changed

4 files changed

+40
-33
lines changed

src/formatter/imp.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@
1717
* Notes:
1818
* Most of this left blank, may add fields later
1919
*/
20-
2120
// Imports
2221
use adwaita::{gio, glib, prelude::*, subclass::prelude::*};
23-
use std::cell::Cell;
2422
use gio::Settings;
25-
use glib::{once_cell::sync::OnceCell, once_cell::sync::Lazy, ParamSpec, Value, FromVariant};
26-
use gtk::{subclass::prelude::*};
23+
use glib::{once_cell::sync::Lazy, once_cell::sync::OnceCell, FromVariant, ParamSpec, Value};
24+
use gtk::subclass::prelude::*;
25+
use std::cell::Cell;
2726

2827
// Modules
2928
//
@@ -32,7 +31,7 @@ use gtk::{subclass::prelude::*};
3231
#[derive(Default)]
3332
pub struct Formatter {
3433
pub settings: OnceCell<Settings>,
35-
pub func: Cell<Option<fn(Vec<String>, Option<Vec<(String, String)>>) -> Option<String>>>
34+
pub func: Cell<Option<fn(Vec<String>, Option<Vec<(String, String)>>) -> Option<String>>>,
3635
}
3736

3837
/// The central trait for subclassing a GObject
@@ -66,10 +65,8 @@ impl Formatter {
6665
pub fn get_setting<T: FromVariant>(&self, name: &str) -> T {
6766
// Return the value of the property
6867
match self.settings.get() {
69-
Some(settings) => {
70-
settings.get::<T>(name)
71-
},
72-
None => panic!("`settings` should be set in `setup_settings`.")
68+
Some(settings) => settings.get::<T>(name),
69+
None => panic!("`settings` should be set in `setup_settings`."),
7370
}
7471
}
7572
}
@@ -173,7 +170,7 @@ impl ObjectImpl for Formatter {
173170

174171
match pspec.name() {
175172
//
176-
_ => panic!("Property `{}` does not exist..", pspec.name())
173+
_ => panic!("Property `{}` does not exist..", pspec.name()),
177174
}
178175
}
179176

@@ -198,7 +195,7 @@ impl ObjectImpl for Formatter {
198195

199196
match pspec.name() {
200197
//
201-
_ => panic!("Property `{}` does not exist..", pspec.name())
198+
_ => panic!("Property `{}` does not exist..", pspec.name()),
202199
}
203200
}
204201
}

src/formatter/mod.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,16 @@
1717
* Notes:
1818
*
1919
*/
20-
2120
// Custom GObjects
2221
mod imp;
2322

2423
// Imports
2524
use adwaita::{gio, glib};
26-
use glib::Object;
2725
use gio::Settings;
26+
use glib::Object;
2827
use gtk::subclass::prelude::*;
2928
// Modules
30-
use crate::{APP_ID};
29+
use crate::APP_ID;
3130

3231
// GObject wrapper for Formatter
3332
glib::wrapper! {
@@ -157,7 +156,7 @@ impl Formatter {
157156

158157
// Use function
159158
let result: Option<String>;
160-
if params.len() > 0 {
159+
if !params.is_empty() {
161160
result = func(vec![parsed_value.to_string()], Some(params));
162161
} else {
163162
result = func(vec![parsed_value.to_string()], None);
@@ -166,8 +165,8 @@ impl Formatter {
166165
self.imp().func.set(Some(func));
167166

168167
result
169-
},
170-
None => panic!("Missing formatting function!")
168+
}
169+
None => panic!("Missing formatting function!"),
171170
}
172171
}
173172
Err(err) => {
@@ -198,10 +197,10 @@ impl Formatter {
198197
*/
199198
impl Default for Formatter {
200199
fn default() -> Self {
201-
let func: fn(Vec<String>, Option<Vec<(String, String)>>) -> Option<String> = |input: Vec<String>, params: Option<Vec<(String, String)>>| {
202-
Some(String::from(input.get(0).unwrap()))
203-
};
204-
200+
let func: fn(Vec<String>, Option<Vec<(String, String)>>) -> Option<String> =
201+
|input: Vec<String>, _params: Option<Vec<(String, String)>>| {
202+
Some(String::from(input.get(0).unwrap()))
203+
};
205204

206205
Self::new(func)
207206
}

src/gpu_page/imp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use glib::{
2626
ToValue, Value,
2727
};
2828
use gtk::{subclass::prelude::*, CompositeTemplate};
29-
use std::{cell::Cell, sync::Arc};
29+
use std::cell::Cell;
3030

3131
// Modules
3232
use crate::provider::Provider;

src/processor/mod.rs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
* It'll be easier to pass a defined "parse_function" to new objects rather than define 3 new classes
1919
* However - getting that working with generics and lifetimes is a bitch..
2020
*/
21-
2221
// Custom GObjects
2322
mod imp;
2423

@@ -28,7 +27,7 @@ use gtk::{gio, glib, prelude::ObjectExt};
2827
use std::ffi::OsStr;
2928

3029
// Crates
31-
use crate::{subprocess::subprocess::exec_communicate};
30+
use crate::subprocess::subprocess::exec_communicate;
3231

3332
// GObject wrapper for Processor
3433
glib::wrapper! {
@@ -100,17 +99,21 @@ impl Processor {
10099
* gpu names:
101100
* This would be called with "","" as params and base-call="nvidia-settings -q GpuUUID -t" start-call="" end-call=""
102101
*/
103-
pub fn process(self, uuid: Option<&str>, property: Option<&str>) -> Result<Option<Vec<String>>, glib::Error> {
102+
pub fn process(
103+
self,
104+
uuid: Option<&str>,
105+
property: Option<&str>,
106+
) -> Result<Option<Vec<String>>, glib::Error> {
104107
//println!("PROCESS BEGINNING");//TEST
105108

106109
// Create call stack of program and args
107-
let mut call_stack: String = self.property("base-call");//"nvidia-smi" OR "nvidia-settings" OR "optirun"
108-
call_stack.push_str(" ");
109-
call_stack.push_str(self.property::<String>("start-call").as_str());//"--query-gpu=" OR "nvidia-smi --query-gpu=" OR ""
110+
let mut call_stack: String = self.property("base-call"); //"nvidia-smi" OR "nvidia-settings" OR "optirun"
111+
call_stack.push(' ');
112+
call_stack.push_str(self.property::<String>("start-call").as_str()); //"--query-gpu=" OR "nvidia-smi --query-gpu=" OR ""
110113
if let Some(property_val) = property {
111114
call_stack.push_str(property_val);
112115
}
113-
call_stack.push_str(self.property::<String>("end-call").as_str());//" --format=csv,noheader -i "
116+
call_stack.push_str(self.property::<String>("end-call").as_str()); //" --format=csv,noheader -i "
114117
if let Some(uuid_val) = uuid {
115118
call_stack.push_str(uuid_val);
116119
}
@@ -176,7 +179,9 @@ impl Processor {
176179
);
177180
}
178181

179-
(Some(stdout_buffer), None) => return Ok(Some(self.parse(&String::from_utf8_lossy(&stdout_buffer)))),
182+
(Some(stdout_buffer), None) => {
183+
return Ok(Some(self.parse(&String::from_utf8_lossy(&stdout_buffer))))
184+
}
180185

181186
(Some(stdout_buffer), Some(stderr_buffer)) => {
182187
println!(
@@ -214,7 +219,9 @@ impl Processor {
214219
);
215220
}
216221

217-
(Some(stdout_buffer), None) => return Ok(Some(self.parse(&String::from_utf8_lossy(&stdout_buffer)))),
222+
(Some(stdout_buffer), None) => {
223+
return Ok(Some(self.parse(&String::from_utf8_lossy(&stdout_buffer))))
224+
}
218225

219226
(Some(stdout_buffer), Some(stderr_buffer)) => {
220227
println!(
@@ -251,7 +258,9 @@ impl Processor {
251258
);
252259
}
253260

254-
(Some(stdout_buffer), None) => return Ok(Some(self.parse(&String::from_utf8_lossy(&stdout_buffer)))),
261+
(Some(stdout_buffer), None) => {
262+
return Ok(Some(self.parse(&String::from_utf8_lossy(&stdout_buffer))))
263+
}
255264

256265
(Some(stdout_buffer), Some(stderr_buffer)) => {
257266
println!(
@@ -283,7 +292,9 @@ impl Processor {
283292
);
284293
}
285294

286-
(Some(stdout_buffer), None) => return Ok(Some(self.parse(&String::from_utf8_lossy(&stdout_buffer)))),
295+
(Some(stdout_buffer), None) => {
296+
return Ok(Some(self.parse(&String::from_utf8_lossy(&stdout_buffer))))
297+
}
287298

288299
(Some(stdout_buffer), Some(stderr_buffer)) => {
289300
println!(

0 commit comments

Comments
 (0)