Resolve clippy warnings

Warnings were mounting up. It was time to resolve them before attempting a massive rebase.
This commit is contained in:
Savanni D'Gerinel 2024-02-07 23:36:03 -05:00
parent 1d6155d9e5
commit 9727d35116
9 changed files with 44 additions and 29 deletions

View File

@ -157,7 +157,7 @@ impl RecordProvider for App {
.map_err(|_| WriteError::Unhandled) .map_err(|_| WriteError::Unhandled)
} }
async fn delete_record(&self, id: RecordId) -> Result<(), WriteError> { async fn delete_record(&self, _id: RecordId) -> Result<(), WriteError> {
unimplemented!() unimplemented!()
} }
} }

View File

@ -15,15 +15,14 @@ You should have received a copy of the GNU General Public License along with Fit
*/ */
use crate::{ use crate::{
app::{App, RecordProvider}, app::App,
types::DayInterval, types::DayInterval,
view_models::DayDetailViewModel, view_models::DayDetailViewModel,
views::{DayDetailView, HistoricalView, PlaceholderView, View, WelcomeView}, views::{DayDetailView, HistoricalView, PlaceholderView, View, WelcomeView},
}; };
use adw::prelude::*; use adw::prelude::*;
use chrono::{Duration, Local}; use chrono::{Duration, Local};
use emseries::Record;
use ft_core::TraxRecord;
use gio::resources_lookup_data; use gio::resources_lookup_data;
use gtk::STYLE_PROVIDER_PRIORITY_USER; use gtk::STYLE_PROVIDER_PRIORITY_USER;
use std::{cell::RefCell, path::PathBuf, rc::Rc}; use std::{cell::RefCell, path::PathBuf, rc::Rc};
@ -126,6 +125,7 @@ impl AppWindow {
s s
} }
#[allow(unused)]
fn show_welcome_view(&self) { fn show_welcome_view(&self) {
let view = View::Welcome(WelcomeView::new({ let view = View::Welcome(WelcomeView::new({
let s = self.clone(); let s = self.clone();
@ -178,6 +178,7 @@ impl AppWindow {
self.layout.append(&current_widget.widget()); self.layout.append(&current_widget.widget());
} }
#[allow(unused)]
fn on_apply_config(&self, path: PathBuf) { fn on_apply_config(&self, path: PathBuf) {
glib::spawn_future_local({ glib::spawn_future_local({
let s = self.clone(); let s = self.clone();

View File

@ -223,6 +223,7 @@ impl DayDetail {
pub struct DayEditPrivate { pub struct DayEditPrivate {
on_finished: RefCell<Box<dyn Fn()>>, on_finished: RefCell<Box<dyn Fn()>>,
#[allow(unused)]
workout_rows: RefCell<gtk::Box>, workout_rows: RefCell<gtk::Box>,
view_model: RefCell<Option<DayDetailViewModel>>, view_model: RefCell<Option<DayDetailViewModel>>,
} }

View File

@ -106,6 +106,7 @@ impl<T: Clone + std::fmt::Debug + 'static> TextEntry<T> {
} }
} }
#[allow(unused)]
pub fn time_field<OnUpdate>( pub fn time_field<OnUpdate>(
value: Option<TimeFormatter>, value: Option<TimeFormatter>,
on_update: OnUpdate, on_update: OnUpdate,
@ -122,6 +123,7 @@ where
) )
} }
#[allow(unused)]
pub fn distance_field<OnUpdate>( pub fn distance_field<OnUpdate>(
value: Option<DistanceFormatter>, value: Option<DistanceFormatter>,
on_update: OnUpdate, on_update: OnUpdate,
@ -138,6 +140,7 @@ where
) )
} }
#[allow(unused)]
pub fn duration_field<OnUpdate>( pub fn duration_field<OnUpdate>(
value: Option<DurationFormatter>, value: Option<DurationFormatter>,
on_update: OnUpdate, on_update: OnUpdate,

View File

@ -15,7 +15,6 @@ You should have received a copy of the GNU General Public License along with Fit
*/ */
use crate::{ use crate::{
components::TextEntry,
types::{FormatOption, WeightFormatter}, types::{FormatOption, WeightFormatter},
}; };
use gtk::prelude::*; use gtk::prelude::*;

View File

@ -53,6 +53,7 @@ impl Iterator for DayIterator {
#[derive(Clone, Copy, Debug, PartialEq, Eq)] #[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum FormatOption { pub enum FormatOption {
Abbreviated, Abbreviated,
#[allow(unused)]
Full, Full,
} }
@ -60,6 +61,7 @@ pub enum FormatOption {
pub struct TimeFormatter(chrono::NaiveTime); pub struct TimeFormatter(chrono::NaiveTime);
impl TimeFormatter { impl TimeFormatter {
#[allow(unused)]
pub fn format(&self, option: FormatOption) -> String { pub fn format(&self, option: FormatOption) -> String {
match option { match option {
FormatOption::Abbreviated => self.0.format("%H:%M"), FormatOption::Abbreviated => self.0.format("%H:%M"),
@ -68,6 +70,7 @@ impl TimeFormatter {
.to_string() .to_string()
} }
#[allow(unused)]
pub fn parse(s: &str) -> Result<TimeFormatter, ParseError> { pub fn parse(s: &str) -> Result<TimeFormatter, ParseError> {
let parts = s let parts = s
.split(':') .split(':')
@ -104,6 +107,7 @@ impl From<chrono::NaiveTime> for TimeFormatter {
pub struct WeightFormatter(si::Kilogram<f64>); pub struct WeightFormatter(si::Kilogram<f64>);
impl WeightFormatter { impl WeightFormatter {
#[allow(unused)]
pub fn format(&self, option: FormatOption) -> String { pub fn format(&self, option: FormatOption) -> String {
match option { match option {
FormatOption::Abbreviated => format!("{} kg", self.0.value_unsafe), FormatOption::Abbreviated => format!("{} kg", self.0.value_unsafe),
@ -111,6 +115,7 @@ impl WeightFormatter {
} }
} }
#[allow(unused)]
pub fn parse(s: &str) -> Result<WeightFormatter, ParseError> { pub fn parse(s: &str) -> Result<WeightFormatter, ParseError> {
s.parse::<f64>() s.parse::<f64>()
.map(|w| WeightFormatter(w * si::KG)) .map(|w| WeightFormatter(w * si::KG))
@ -149,6 +154,7 @@ impl From<si::Kilogram<f64>> for WeightFormatter {
pub struct DistanceFormatter(si::Meter<f64>); pub struct DistanceFormatter(si::Meter<f64>);
impl DistanceFormatter { impl DistanceFormatter {
#[allow(unused)]
pub fn format(&self, option: FormatOption) -> String { pub fn format(&self, option: FormatOption) -> String {
match option { match option {
FormatOption::Abbreviated => format!("{} km", self.0.value_unsafe / 1000.), FormatOption::Abbreviated => format!("{} km", self.0.value_unsafe / 1000.),
@ -156,6 +162,7 @@ impl DistanceFormatter {
} }
} }
#[allow(unused)]
pub fn parse(s: &str) -> Result<DistanceFormatter, ParseError> { pub fn parse(s: &str) -> Result<DistanceFormatter, ParseError> {
let value = s.parse::<f64>().map_err(|_| ParseError)?; let value = s.parse::<f64>().map_err(|_| ParseError)?;
Ok(DistanceFormatter(value * 1000. * si::M)) Ok(DistanceFormatter(value * 1000. * si::M))
@ -193,6 +200,7 @@ impl From<si::Meter<f64>> for DistanceFormatter {
pub struct DurationFormatter(si::Second<f64>); pub struct DurationFormatter(si::Second<f64>);
impl DurationFormatter { impl DurationFormatter {
#[allow(unused)]
pub fn format(&self, option: FormatOption) -> String { pub fn format(&self, option: FormatOption) -> String {
let (hours, minutes) = self.hours_and_minutes(); let (hours, minutes) = self.hours_and_minutes();
let (h, m) = match option { let (h, m) = match option {
@ -206,11 +214,13 @@ impl DurationFormatter {
} }
} }
#[allow(unused)]
pub fn parse(s: &str) -> Result<DurationFormatter, ParseError> { pub fn parse(s: &str) -> Result<DurationFormatter, ParseError> {
let value = s.parse::<f64>().map_err(|_| ParseError)?; let value = s.parse::<f64>().map_err(|_| ParseError)?;
Ok(DurationFormatter(value * 60. * si::S)) Ok(DurationFormatter(value * 60. * si::S))
} }
#[allow(unused)]
fn hours_and_minutes(&self) -> (i64, i64) { fn hours_and_minutes(&self) -> (i64, i64) {
let minutes: i64 = (self.0.value_unsafe / 60.).round() as i64; let minutes: i64 = (self.0.value_unsafe / 60.).round() as i64;
let hours: i64 = minutes / 60; let hours: i64 = minutes / 60;

View File

@ -14,11 +14,13 @@ General Public License for more details.
You should have received a copy of the GNU General Public License along with FitnessTrax. If not, see <https://www.gnu.org/licenses/>. You should have received a copy of the GNU General Public License along with FitnessTrax. If not, see <https://www.gnu.org/licenses/>.
*/ */
#[allow(unused_imports)]
use crate::app::{ReadError, RecordProvider, WriteError}; use crate::app::{ReadError, RecordProvider, WriteError};
#[allow(unused_imports)]
use chrono::NaiveDate; use chrono::NaiveDate;
use dimensioned::si; use dimensioned::si;
use emseries::{Record, RecordId, Recordable}; use emseries::{Record, RecordId, Recordable};
use ft_core::{RecordType, TimeDistance, TimeDistanceWorkoutType, TraxRecord}; use ft_core::{TimeDistance, TimeDistanceWorkoutType, TraxRecord};
use std::{ use std::{
collections::HashMap, collections::HashMap,
ops::Deref, ops::Deref,
@ -46,10 +48,10 @@ impl<T: Clone + emseries::Recordable> RecordState<T> {
fn exists(&self) -> bool { fn exists(&self) -> bool {
match self { match self {
RecordState::Original(ref r) => true, RecordState::Original(ref _r) => true,
RecordState::New(ref r) => true, RecordState::New(ref _r) => true,
RecordState::Updated(ref r) => true, RecordState::Updated(ref _r) => true,
RecordState::Deleted(ref r) => false, RecordState::Deleted(ref _r) => false,
} }
} }
@ -158,7 +160,7 @@ impl DayDetailViewModel {
} }
pub fn weight(&self) -> Option<si::Kilogram<f64>> { pub fn weight(&self) -> Option<si::Kilogram<f64>> {
(*self.weight.read().unwrap()).as_ref().map(|w| (*w).weight) (*self.weight.read().unwrap()).as_ref().map(|w| w.weight)
} }
pub fn set_weight(&self, new_weight: si::Kilogram<f64>) { pub fn set_weight(&self, new_weight: si::Kilogram<f64>) {
@ -220,7 +222,7 @@ impl DayDetailViewModel {
let data = workout.data.clone(); let data = workout.data.clone();
let mut record_set = self.records.write().unwrap(); let mut record_set = self.records.write().unwrap();
if let Some(record_state) = record_set.get(&id).clone() { if let Some(record_state) = record_set.get(&id) {
let updated_state = match **record_state { let updated_state = match **record_state {
TraxRecord::BikeRide(_) => { TraxRecord::BikeRide(_) => {
Some(record_state.clone().with_value(TraxRecord::BikeRide(data))) Some(record_state.clone().with_value(TraxRecord::BikeRide(data)))
@ -281,15 +283,13 @@ impl DayDetailViewModel {
) )
} }
#[allow(unused)]
fn get_record(&self, id: &RecordId) -> Option<Record<TraxRecord>> { fn get_record(&self, id: &RecordId) -> Option<Record<TraxRecord>> {
let record_set = self.records.read().unwrap(); let record_set = self.records.read().unwrap();
match record_set.get(&id) { record_set.get(id).map(|record| Record {
Some(record) => Some(Record {
id: id.clone(), id: id.clone(),
data: (**record).clone(), data: (**record).clone(),
}), })
None => None,
}
} }
pub fn remove_record(&self, id: RecordId) { pub fn remove_record(&self, id: RecordId) {
@ -486,28 +486,28 @@ mod test {
Record { Record {
id: RecordId::default(), id: RecordId::default(),
data: TraxRecord::Weight(ft_core::Weight { data: TraxRecord::Weight(ft_core::Weight {
date: oct_12.clone(), date: oct_12,
weight: 93. * si::KG, weight: 93. * si::KG,
}), }),
}, },
Record { Record {
id: RecordId::default(), id: RecordId::default(),
data: TraxRecord::Weight(ft_core::Weight { data: TraxRecord::Weight(ft_core::Weight {
date: oct_13.clone(), date: oct_13,
weight: 95. * si::KG, weight: 95. * si::KG,
}), }),
}, },
Record { Record {
id: RecordId::default(), id: RecordId::default(),
data: TraxRecord::Steps(ft_core::Steps { data: TraxRecord::Steps(ft_core::Steps {
date: oct_13.clone(), date: oct_13,
count: 2500, count: 2500,
}), }),
}, },
Record { Record {
id: RecordId::default(), id: RecordId::default(),
data: TraxRecord::BikeRide(ft_core::TimeDistance { data: TraxRecord::BikeRide(ft_core::TimeDistance {
datetime: oct_13_am.clone(), datetime: oct_13_am,
distance: Some(15000. * si::M), distance: Some(15000. * si::M),
duration: Some(3600. * si::S), duration: Some(3600. * si::S),
comments: Some("somecomments present".to_owned()), comments: Some("somecomments present".to_owned()),
@ -522,7 +522,7 @@ mod test {
#[tokio::test] #[tokio::test]
async fn it_honors_only_the_first_weight_and_step_record() { async fn it_honors_only_the_first_weight_and_step_record() {
let (view_model, provider) = create_view_model().await; let (view_model, _provider) = create_view_model().await;
assert_eq!(view_model.weight(), Some(95. * si::KG)); assert_eq!(view_model.weight(), Some(95. * si::KG));
assert_eq!(view_model.steps(), Some(2500)); assert_eq!(view_model.steps(), Some(2500));
} }
@ -647,7 +647,7 @@ mod test {
#[tokio::test] #[tokio::test]
async fn it_can_delete_an_existing_record() { async fn it_can_delete_an_existing_record() {
let (view_model, provider) = create_view_model().await; let (view_model, provider) = create_view_model().await;
let mut workout = view_model let workout = view_model
.time_distance_records(TimeDistanceWorkoutType::BikeRide) .time_distance_records(TimeDistanceWorkoutType::BikeRide)
.first() .first()
.cloned() .cloned()

View File

@ -17,12 +17,12 @@ You should have received a copy of the GNU General Public License along with Fit
use crate::{ use crate::{
app::App, components::DaySummary, types::DayInterval, view_models::DayDetailViewModel, app::App, components::DaySummary, types::DayInterval, view_models::DayDetailViewModel,
}; };
use chrono::NaiveDate;
use emseries::Record;
use ft_core::TraxRecord;
use glib::Object; use glib::Object;
use gtk::{prelude::*, subclass::prelude::*}; use gtk::{prelude::*, subclass::prelude::*};
use std::{cell::RefCell, collections::HashMap, rc::Rc}; use std::{cell::RefCell, rc::Rc};
/// The historical view will show a window into the main database. It will show some version of /// The historical view will show a window into the main database. It will show some version of
/// daily summaries, daily details, and will provide all functions the user may need for editing /// daily summaries, daily details, and will provide all functions the user may need for editing

View File

@ -30,6 +30,7 @@ pub use welcome_view::WelcomeView;
pub enum View { pub enum View {
Placeholder(PlaceholderView), Placeholder(PlaceholderView),
#[allow(unused)]
Welcome(WelcomeView), Welcome(WelcomeView),
Historical(HistoricalView), Historical(HistoricalView),
} }