Applied clippy

pull/6/head
Benedikt Terhechte 3 years ago
parent 74a1bf7872
commit 936aa55703

@ -72,7 +72,7 @@ pub fn value_from_field<'stmt>(field: &Field, row: &Row<'stmt>) -> Result<ValueF
Path | SenderDomain | SenderLocalPart | SenderName | ToGroup | ToName | ToAddress
| Subject => {
let string: String = row.get::<&str, String>(field.as_str())?;
return Ok(ValueField::string(field, &string));
Ok(ValueField::string(field, &string))
}
Year | Month | Day | Timestamp => {
return Ok(ValueField::usize(
@ -84,10 +84,10 @@ pub fn value_from_field<'stmt>(field: &Field, row: &Row<'stmt>) -> Result<ValueF
let tag_string = row.get::<&str, String>(field.as_str())?;
let tags =
crate::importer::formats::shared::email::EmailMeta::tags_from_string(&tag_string);
return Ok(ValueField::array(
Ok(ValueField::array(
field,
tags.into_iter().map(|f| Value::String(f)).collect(),
));
tags.into_iter().map(Value::String).collect(),
))
}
IsReply | IsSend | MetaIsSeen => {
return Ok(ValueField::bool(

@ -53,7 +53,7 @@ impl Database {
Some(n) => n,
None => bail!("No connection to database available in query"),
};
let mut stmt = connection.prepare(&QUERY_COUNT_MAILS)?;
let mut stmt = connection.prepare(QUERY_COUNT_MAILS)?;
let count: usize = stmt.query_row([], |q| q.get(0))?;
Ok(count)
}
@ -61,7 +61,7 @@ impl Database {
pub fn save_config(&self, config: Config) -> Result<()> {
let fields = config
.into_fields()
.ok_or(eyre::eyre!("Could not create fields from config"))?;
.ok_or_else(|| eyre::eyre!("Could not create fields from config"))?;
self.insert_config_fields(fields)
}
@ -181,7 +181,7 @@ impl Database {
Some(n) => n,
None => bail!("No connection to database available in query"),
};
let mut stmt = connection.prepare(&QUERY_SELECT_META)?;
let mut stmt = connection.prepare(QUERY_SELECT_META)?;
let mut query_results = HashMap::new();
let mut rows = stmt.query([])?;
while let Some(row) = rows.next()? {
@ -205,7 +205,7 @@ impl Database {
Some(n) => n,
None => bail!("No connection to database available in query"),
};
let mut stmt = connection.prepare(&QUERY_INSERT_META)?;
let mut stmt = connection.prepare(QUERY_INSERT_META)?;
for (key, value) in fields {
stmt.execute(params![key, value])?;
}

@ -5,7 +5,7 @@ use crate::importer::EmailEntry;
/// Parameter for sending work to the database during `import`.
pub enum DBMessage {
/// Send for a successfuly parsed mail
Mail(EmailEntry),
Mail(Box<EmailEntry>),
/// Send for any kind of error during reading / parsing
Error(Report),
/// Send once all parsing is done.

@ -131,6 +131,7 @@ impl ValueField {
&self.value
}
#[allow(clippy::inherent_to_string)]
pub fn to_string(&self) -> String {
match &self.value {
Value::String(s) => s.clone(),

@ -46,7 +46,7 @@ impl App for PostsackApp {
ctx.set_pixels_per_point(pixels * 1.2);
// If there is a platform error, display it
if let Some(e) = super::platform::initial_update(&ctx).err() {
if let Some(e) = super::platform::initial_update(ctx).err() {
self.state = StateUI::error(e);
}
}

@ -59,10 +59,8 @@ impl ErrorUI {
ui.label(format!("{}", &self.report));
ui.add_space(20.0);
ui.horizontal(|ui| {
if self.config.is_some() {
if ui.button("Try Again").clicked() {
self.action_back = true;
}
if self.config.is_some() && ui.button("Try Again").clicked() {
self.action_back = true;
}
ui.add_space(125.0);
if ui.button("Quit").clicked() {

@ -322,7 +322,7 @@ impl ImporterUI {
} = self.adapter.finished()?;
if finishing {
label = format!("Finishing Up");
label = "Finishing Up".into();
}
Ok(InternalAdapterState {
label,

@ -81,7 +81,7 @@ impl StateUI {
StateUIAction::ImportDone { config, total } => {
*self = match main::MainUI::new(config.clone(), total) {
Ok(n) => StateUI::Main(n),
Err(e) => StateUI::Error(ErrorUI::new(e, Some(config.clone()))),
Err(e) => StateUI::Error(ErrorUI::new(e, Some(config))),
};
}
StateUIAction::Close { config } => {
@ -131,7 +131,7 @@ impl StateUI {
match main::MainUI::new(config.clone(), total) {
Ok(n) => StateUI::Main(n),
Err(e) => StateUI::Error(ErrorUI::new(e, Some(config.clone()))),
Err(e) => StateUI::Error(ErrorUI::new(e, Some(config))),
}
}
@ -139,7 +139,7 @@ impl StateUI {
let importer = match import::ImporterUI::new(config.clone()) {
Ok(n) => n,
Err(e) => {
return StateUI::Error(error::ErrorUI::new(e, Some(config.clone())));
return StateUI::Error(error::ErrorUI::new(e, Some(config)));
}
};

@ -126,7 +126,7 @@ impl StartupUI {
let mut txt = self
.email_address
.clone()
.unwrap_or("john@example.org".to_string());
.unwrap_or_else(|| "john@example.org".to_string());
let response = ui.allocate_ui_at_rect(center, |ui| {
// We use a grid as that gives us more spacing opportunities
@ -154,10 +154,8 @@ impl StartupUI {
if ui.button("Browse...").clicked() {
self.open_email_folder_dialog()
}
if self.format == FormatType::AppleMail {
if ui.button("or Mail.app default folder").clicked() {
self.email_folder = self.format.default_path();
}
if self.format == FormatType::AppleMail && ui.button("or Mail.app default folder").clicked(){
self.email_folder = self.format.default_path();
}
});
ui.end_row();
@ -258,16 +256,16 @@ impl StartupUI {
let emails: Vec<String> = self
.email_address
.iter()
.map(|e| e.split(",").map(|e| e.trim().to_string()).collect())
.map(|e| e.split(',').map(|e| e.trim().to_string()).collect())
.collect();
if !email.exists() {
self.error_message = Some(format!("Email folder doesn't exist"));
self.error_message = Some("Email folder doesn't exist".into());
return;
}
if self.save_to_disk && !self.database_path.is_some() {
self.error_message = Some(format!("Please select a database folder"));
if self.save_to_disk && self.database_path.is_none() {
self.error_message = Some("Please select a database folder".into());
return;
}
@ -293,7 +291,7 @@ impl StartupUI {
let mut selected = self.format;
egui::ComboBox::from_id_source("mailbox_type_combobox")
.width(width)
.selected_text(format!("{}", selected.name()))
.selected_text(selected.name())
.show_ui(ui, |ui| {
for format in FormatType::all_cases() {
ui.selectable_value(&mut selected, format, format.name());
@ -307,7 +305,7 @@ impl StartupUI {
let default_path = self
.format
.default_path()
.unwrap_or(std::path::Path::new(&fallback.to_string()).to_path_buf());
.unwrap_or_else(|| std::path::Path::new(&fallback.to_string()).to_path_buf());
let folder = match tinyfiledialogs::select_folder_dialog(
"Select folder",

@ -43,61 +43,59 @@ impl<'a> Widget for NavigationBar<'a> {
ui.visuals_mut().widgets.active.corner_radius = 5.0;
ui.visuals_mut().widgets.hovered.corner_radius = 5.0;
let response = ui
.horizontal(|ui| {
ui.set_height(40.0);
ui.add_space(15.0);
let close_text = "Close";
if ui.add(navigation_button(close_text)).clicked() {
self.state.action_close = true;
}
let filter_text = "\u{1f50D} Filters";
let filter_response = ui.add(navigation_button(filter_text));
let popup_id = ui.make_persistent_id("filter_panel_id");
super::widgets::popover(ui, popup_id, &filter_response, |ui| {
ui.add(FilterPanel::new(self.engine, self.filter_state, self.error));
});
ui.add(Label::new(format!(
"{} Mails",
self.total_mails.to_formatted_string(&Locale::en)
)));
// This is a hack to get right-alignment.
// we can't size the button, we can only size text. We will size text
// and then use ~that for these buttons
let mut w = ui.available_width();
let mail_text = "\u{1F4E7} Mails";
let mail_galley = ui.painter().layout_no_wrap(
mail_text.to_owned(),
egui::TextStyle::Button,
Color32::WHITE,
);
// FIXME: Add support for exporting the selected mails as deletion rules
// let filter_text = "\u{1F5B9} Export";
// let filter_galley = ui.painter().layout_no_wrap(
// filter_text.to_owned(),
// egui::TextStyle::Button,
// Color32::WHITE,
// );
w -= mail_galley.size().x + ui.spacing().button_padding.x * 4.0;
//w -= filter_galley.size().x + ui.spacing().button_padding.x * 4.0;
ui.add_space(w);
//ui.add(navigation_button(filter_text));
if ui.add(navigation_button(mail_text)).clicked() {
self.state.show_emails = !self.state.show_emails;
}
})
.response;
response
ui.horizontal(|ui| {
ui.set_height(40.0);
ui.add_space(15.0);
let close_text = "Close";
if ui.add(navigation_button(close_text)).clicked() {
self.state.action_close = true;
}
let filter_text = "\u{1f50D} Filters";
let filter_response = ui.add(navigation_button(filter_text));
let popup_id = ui.make_persistent_id("filter_panel_id");
super::widgets::popover(ui, popup_id, &filter_response, |ui| {
ui.add(FilterPanel::new(self.engine, self.filter_state, self.error));
});
ui.add(Label::new(format!(
"{} Mails",
self.total_mails.to_formatted_string(&Locale::en)
)));
// This is a hack to get right-alignment.
// we can't size the button, we can only size text. We will size text
// and then use ~that for these buttons
let mut w = ui.available_width();
let mail_text = "\u{1F4E7} Mails";
let mail_galley = ui.painter().layout_no_wrap(
mail_text.to_owned(),
egui::TextStyle::Button,
Color32::WHITE,
);
// FIXME: Add support for exporting the selected mails as deletion rules
// let filter_text = "\u{1F5B9} Export";
// let filter_galley = ui.painter().layout_no_wrap(
// filter_text.to_owned(),
// egui::TextStyle::Button,
// Color32::WHITE,
// );
w -= mail_galley.size().x + ui.spacing().button_padding.x * 4.0;
//w -= filter_galley.size().x + ui.spacing().button_padding.x * 4.0;
ui.add_space(w);
//ui.add(navigation_button(filter_text));
if ui.add(navigation_button(mail_text)).clicked() {
self.state.show_emails = !self.state.show_emails;
}
})
.response
}
}

@ -83,7 +83,7 @@ fn install_fonts(egui_ctx: &egui::CtxRef) {
] {
fonts
.font_data
.insert(key.to_owned(), std::borrow::Cow::Borrowed(&data));
.insert(key.to_owned(), std::borrow::Cow::Borrowed(data));
fonts
.fonts_for_family
.get_mut(&family)

@ -45,7 +45,7 @@ pub enum Theme {
}
impl Theme {
pub fn to_visuals(&self) -> Visuals {
pub fn visuals(&self) -> Visuals {
match self {
Theme::Light => egui::Visuals::light(),
Theme::Dark => egui::Visuals::dark(),
@ -67,7 +67,7 @@ pub fn setup(ctx: &egui::CtxRef, theme: Theme) {
.set(module::platform_colors(theme))
.expect("Could not setup colors");
let colors = module::platform_colors(theme);
let mut visuals = theme.to_visuals();
let mut visuals = theme.visuals();
visuals.widgets.noninteractive.bg_fill = colors.window_background;
ctx.set_visuals(visuals);
module::setup(ctx)

@ -149,7 +149,7 @@ impl<'a> AnimatedBackground<'a> {
// the fill color is based on the added block count
color_adder += *n;
let color_addition = if colors.is_light {
-1 * (color_adder % 50) as i8
-((color_adder % 50) as i8)
} else {
(color_adder % 50) as i8
};

@ -23,9 +23,10 @@ pub struct FilterState {
impl FilterState {
pub fn new() -> Self {
let mut basic = Self::default();
basic.is_send = Some(false);
basic
FilterState {
is_send: Some(false),
..Default::default()
}
}
fn apply(&self, engine: &mut Engine, error: &mut Option<Report>) {
@ -213,7 +214,7 @@ fn radio_group(ui: &mut egui::Ui, title: &str, names: &[&str; 3], value: &mut Op
}
fn input_block(ui: &mut egui::Ui, title: &str, value: &mut Option<String>) {
let mut text_value = value.clone().unwrap_or("".to_string());
let mut text_value = value.clone().unwrap_or_else(|| "".to_string());
ui.label(title);
ui.text_edit_singleline(&mut text_value);
match text_value.as_str() {

@ -9,7 +9,7 @@ pub fn popover(
ui: &Ui,
popup_id: Id,
widget_response: &Response,
add_contents: impl FnOnce(&mut Ui) -> (),
add_contents: impl FnOnce(&mut Ui),
) {
if widget_response.clicked() {
ui.memory().toggle_popup(popup_id);

@ -46,7 +46,7 @@ impl<'a> Widget for Rectangles<'a> {
for (index, item) in items.iter().enumerate() {
let item_response = ui.put(
item.layout_rect(),
rectangle(&item, active, colors.content_background, index, total),
rectangle(item, active, colors.content_background, index, total),
);
if item_response.clicked() && active {
*self.error = self.engine.push(item.clone()).err();
@ -57,9 +57,8 @@ impl<'a> Widget for Rectangles<'a> {
}
}
if let Some(h) = hovered {
if let Some(text) = hovered {
// Calculate the size
let text = format!("{}", h);
let galley = ui
.painter()
.layout_no_wrap(text.clone(), TextStyle::Body, Color32::WHITE);

@ -73,7 +73,7 @@ pub fn read_emails(config: &Config, sender: MessageSender) -> Result<Vec<Mail>>
tracing::error!("{} {:?}", path.display(), &e);
if let Err(e) = sender.send(Message::Error(eyre!(
"Could read mails in {}: {:?}",
path.clone().display(),
path.display(),
e
))) {
tracing::error!("Error sending error {}", e);

@ -42,7 +42,7 @@ pub fn into_database<Mail: ParseableEmail + 'static>(
.for_each(|entry| {
// Try to write the message into the database
if let Err(e) = match entry {
Ok(mail) => sender.send(DBMessage::Mail(mail)),
Ok(mail) => sender.send(DBMessage::Mail(Box::new(mail))),
Err(e) => sender.send(DBMessage::Error(e)),
} {
tracing::error!("Error Inserting into Database: {:?}", &e);

@ -1,6 +1,7 @@
use crossbeam_channel;
pub(crate) mod formats;
#[allow(clippy::module_inception)]
mod importer;
mod message_adapter;

@ -123,7 +123,7 @@ impl Engine {
// Add the next group by
let index = self.group_by_stack.len();
let next = default_group_by_stack(index)
.ok_or(eyre::eyre!("default group by stack out of bounds"))?;
.ok_or_else(|| eyre::eyre!("default group by stack out of bounds"))?;
self.group_by_stack.push(next);
// Block UI & Wait for updates

@ -91,6 +91,7 @@ pub fn set_filters(engine: &mut Engine, filters: &[Filter]) -> Result<()> {
/// * `engine` - The engine to use for retrieving data
/// * `aggregation` - The aggregation to return the fields for. Required to also return the current aggregation field.
pub fn aggregation_fields(engine: &Engine, aggregation: &Aggregation) -> Vec<Field> {
#[allow(clippy::unnecessary_filter_map)]
Field::all_cases()
.filter_map(|f| {
if f == aggregation.field {

@ -35,7 +35,7 @@ impl Segmentation {
rect.width() as f64,
rect.height() as f64,
);
layout.layout_items(&mut self.items(), bounds);
layout.layout_items(self.items(), bounds);
}
/// The total amount of items in all the `Segments`.

@ -102,9 +102,9 @@ impl Config {
// The following fields are of version 1.0, so they should aways exist
let emails_folder_path_str = fields
.get("emails_folder_path")
.ok_or(eyre!("Missing config field emails_folder_path"))?
.ok_or_else(|| eyre!("Missing config field emails_folder_path"))?
.as_str()
.ok_or(eyre!("Invalid field type for emails_folder_path"))?;
.ok_or_else(|| eyre!("Invalid field type for emails_folder_path"))?;
let emails_folder_path = PathBuf::from_str(emails_folder_path_str).map_err(|e| {
eyre!(
"Invalid emails_folder_path: {}: {}",
@ -112,25 +112,26 @@ impl Config {
e
)
})?;
#[allow(clippy::needless_collect)]
let sender_emails: Vec<String> = fields
.get("sender_emails")
.map(|v| v.as_str().map(|e| e.to_string()))
.flatten()
.ok_or(eyre!("Missing config field sender_emails"))?
.split(",")
.ok_or_else(|| eyre!("Missing config field sender_emails"))?
.split(',')
.map(|e| e.trim().to_owned())
.collect();
let format = fields
.get("format")
.map(|e| e.as_str())
.flatten()
.map(|e| FormatType::from(e))
.ok_or(eyre!("Missing config field format_type"))?;
.map(FormatType::from)
.ok_or_else(|| eyre!("Missing config field format_type"))?;
let persistent = fields
.get("persistent")
.map(|e| e.as_bool())
.flatten()
.ok_or(eyre!("Missing config field persistent"))?;
.ok_or_else(|| eyre!("Missing config field persistent"))?;
Ok(Config {
database_path: path.as_ref().to_path_buf(),
emails_folder_path,
@ -186,7 +187,7 @@ impl Config {
"sender_emails".to_owned(),
self.sender_emails
.iter()
.map(|e| e.clone())
.cloned()
.collect::<Vec<String>>()
.join(",")
.into(),

@ -45,8 +45,7 @@ mod tests {
// Add a filter
let filter = Filter::Is(ValueField::bool(&Field::IsSend, true));
model::segmentations::set_filters(&mut engine, &vec![filter])
.expect("Expect setting filters");
model::segmentations::set_filters(&mut engine, &[filter]).expect("Expect setting filters");
engine.wait().expect("");
let segments =

@ -35,6 +35,7 @@ mod tests {
});
let mails = mails.expect("Expected Mails");
#[allow(clippy::needless_collect)]
let subjects: Vec<String> = mails
.into_iter()
.map(|s| match s {

Loading…
Cancel
Save