Small refactors to avoid implicit unwrap() panics
parent
0201241786
commit
8f63572584
|
@ -250,8 +250,8 @@ pub trait MailBackend: ::std::fmt::Debug + Send + Sync {
|
|||
fn get(&mut self, folder: &Folder) -> Async<Result<Vec<Envelope>>>;
|
||||
fn refresh(
|
||||
&mut self,
|
||||
folder_hash: FolderHash,
|
||||
sender: RefreshEventConsumer,
|
||||
_folder_hash: FolderHash,
|
||||
_sender: RefreshEventConsumer,
|
||||
) -> Result<Async<Result<Vec<RefreshEvent>>>> {
|
||||
Err(MeliError::new("Unimplemented."))
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ pub trait TextProcessing: UnicodeSegmentation + CodePointsIter {
|
|||
fn grapheme_width(&self) -> usize {
|
||||
let mut count = 0;
|
||||
for c in self.code_points() {
|
||||
count += if let Some(w) = wcwidth(c) { w } else { 0 };
|
||||
count += wcwidth(c).unwrap_or(0);
|
||||
}
|
||||
|
||||
count
|
||||
|
|
|
@ -13,7 +13,7 @@ pub trait Truncate {
|
|||
}
|
||||
|
||||
impl Truncate for &mut String {
|
||||
fn truncate_at_boundary(self, mut new_len: usize) {
|
||||
fn truncate_at_boundary(self, new_len: usize) {
|
||||
if new_len >= self.len() {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -257,7 +257,7 @@ impl fmt::Display for Listing {
|
|||
impl Component for Listing {
|
||||
fn draw(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) {
|
||||
for i in 0..context.accounts.len() {
|
||||
context.is_online(i);
|
||||
let _ = context.is_online(i);
|
||||
}
|
||||
|
||||
if !self.is_dirty() {
|
||||
|
@ -405,21 +405,25 @@ impl Component for Listing {
|
|||
}
|
||||
_ => return false,
|
||||
}
|
||||
let folder_hash =
|
||||
context.accounts[self.cursor_pos.0].folders_order[self.cursor_pos.1];
|
||||
/* Check if per-folder configuration overrides general configuration */
|
||||
if let Some(index_style) = context
|
||||
.accounts
|
||||
.get(self.cursor_pos.0)
|
||||
.and_then(|account| account.folder_confs(folder_hash).conf_override.index_style)
|
||||
/* Account might have no folders yet if it's offline */
|
||||
if let Some(&folder_hash) = context.accounts[self.cursor_pos.0]
|
||||
.folders_order
|
||||
.get(self.cursor_pos.1)
|
||||
{
|
||||
self.component.set_style(index_style);
|
||||
} else if let Some(index_style) = context
|
||||
.accounts
|
||||
.get(self.cursor_pos.0)
|
||||
.and_then(|account| Some(account.settings.conf.index_style()))
|
||||
{
|
||||
self.component.set_style(index_style);
|
||||
/* Check if per-folder configuration overrides general configuration */
|
||||
if let Some(index_style) =
|
||||
context.accounts.get(self.cursor_pos.0).and_then(|account| {
|
||||
account.folder_confs(folder_hash).conf_override.index_style
|
||||
})
|
||||
{
|
||||
self.component.set_style(index_style);
|
||||
} else if let Some(index_style) = context
|
||||
.accounts
|
||||
.get(self.cursor_pos.0)
|
||||
.and_then(|account| Some(account.settings.conf.index_style()))
|
||||
{
|
||||
self.component.set_style(index_style);
|
||||
}
|
||||
}
|
||||
context
|
||||
.replies
|
||||
|
|
|
@ -708,15 +708,13 @@ impl CompactListing {
|
|||
for (idx, root_idx) in threads_iter.enumerate() {
|
||||
self.length += 1;
|
||||
let thread_node = &threads.thread_nodes()[&root_idx];
|
||||
let i = if let Some(i) = thread_node.message() {
|
||||
i
|
||||
} else {
|
||||
let i = thread_node.message().unwrap_or_else(|| {
|
||||
let mut iter_ptr = thread_node.children()[0];
|
||||
while threads.thread_nodes()[&iter_ptr].message().is_none() {
|
||||
iter_ptr = threads.thread_nodes()[&iter_ptr].children()[0];
|
||||
}
|
||||
threads.thread_nodes()[&iter_ptr].message().unwrap()
|
||||
};
|
||||
});
|
||||
if !context.accounts[self.cursor_pos.0].contains_key(i) {
|
||||
debug!("key = {}", i);
|
||||
debug!(
|
||||
|
@ -808,15 +806,13 @@ impl CompactListing {
|
|||
|
||||
for ((idx, root_idx), strings) in threads_iter.enumerate().zip(rows) {
|
||||
let thread_node = &threads.thread_nodes()[&root_idx];
|
||||
let i = if let Some(i) = thread_node.message() {
|
||||
i
|
||||
} else {
|
||||
let i = thread_node.message().unwrap_or_else(|| {
|
||||
let mut iter_ptr = thread_node.children()[0];
|
||||
while threads.thread_nodes()[&iter_ptr].message().is_none() {
|
||||
iter_ptr = threads.thread_nodes()[&iter_ptr].children()[0];
|
||||
}
|
||||
threads.thread_nodes()[&iter_ptr].message().unwrap()
|
||||
};
|
||||
});
|
||||
if !context.accounts[self.cursor_pos.0].contains_key(i) {
|
||||
//debug!("key = {}", i);
|
||||
//debug!(
|
||||
|
@ -1327,19 +1323,21 @@ impl Component for CompactListing {
|
|||
}
|
||||
match *event {
|
||||
UIEvent::MailboxUpdate((ref idxa, ref idxf))
|
||||
if (*idxa, *idxf)
|
||||
== (
|
||||
self.new_cursor_pos.0,
|
||||
context.accounts[self.new_cursor_pos.0].folders_order
|
||||
[self.new_cursor_pos.1],
|
||||
) =>
|
||||
if context.accounts[self.new_cursor_pos.0]
|
||||
.folders_order
|
||||
.get(self.new_cursor_pos.1)
|
||||
.map(|&folder_hash| (*idxa, *idxf) == (self.new_cursor_pos.0, folder_hash))
|
||||
.unwrap_or(false) =>
|
||||
{
|
||||
self.refresh_mailbox(context);
|
||||
self.set_dirty(true);
|
||||
}
|
||||
UIEvent::StartupCheck(ref f)
|
||||
if *f
|
||||
== context.accounts[self.cursor_pos.0].folders_order[self.new_cursor_pos.1] =>
|
||||
if context.accounts[self.new_cursor_pos.0]
|
||||
.folders_order
|
||||
.get(self.new_cursor_pos.1)
|
||||
.map(|&folder_hash| *f == folder_hash)
|
||||
.unwrap_or(false) =>
|
||||
{
|
||||
self.refresh_mailbox(context);
|
||||
self.set_dirty(true);
|
||||
|
|
|
@ -670,15 +670,13 @@ impl ConversationsListing {
|
|||
for (idx, root_idx) in threads_iter.enumerate() {
|
||||
self.length += 1;
|
||||
let thread_node = &threads.thread_nodes()[&root_idx];
|
||||
let i = if let Some(i) = thread_node.message() {
|
||||
i
|
||||
} else {
|
||||
let i = thread_node.message().unwrap_or_else(|| {
|
||||
let mut iter_ptr = thread_node.children()[0];
|
||||
while threads.thread_nodes()[&iter_ptr].message().is_none() {
|
||||
iter_ptr = threads.thread_nodes()[&iter_ptr].children()[0];
|
||||
}
|
||||
threads.thread_nodes()[&iter_ptr].message().unwrap()
|
||||
};
|
||||
});
|
||||
if !context.accounts[self.cursor_pos.0].contains_key(i) {
|
||||
debug!("key = {}", i);
|
||||
debug!(
|
||||
|
@ -771,15 +769,13 @@ impl ConversationsListing {
|
|||
|
||||
for ((idx, root_idx), strings) in threads_iter.enumerate().zip(rows) {
|
||||
let thread_node = &threads.thread_nodes()[&root_idx];
|
||||
let i = if let Some(i) = thread_node.message() {
|
||||
i
|
||||
} else {
|
||||
let i = thread_node.message().unwrap_or_else(|| {
|
||||
let mut iter_ptr = thread_node.children()[0];
|
||||
while threads.thread_nodes()[&iter_ptr].message().is_none() {
|
||||
iter_ptr = threads.thread_nodes()[&iter_ptr].children()[0];
|
||||
}
|
||||
threads.thread_nodes()[&iter_ptr].message().unwrap()
|
||||
};
|
||||
});
|
||||
if !context.accounts[self.cursor_pos.0].contains_key(i) {
|
||||
panic!();
|
||||
}
|
||||
|
@ -1345,19 +1341,21 @@ impl Component for ConversationsListing {
|
|||
}
|
||||
match *event {
|
||||
UIEvent::MailboxUpdate((ref idxa, ref idxf))
|
||||
if (*idxa, *idxf)
|
||||
== (
|
||||
self.new_cursor_pos.0,
|
||||
context.accounts[self.new_cursor_pos.0].folders_order
|
||||
[self.new_cursor_pos.1],
|
||||
) =>
|
||||
if context.accounts[self.new_cursor_pos.0]
|
||||
.folders_order
|
||||
.get(self.new_cursor_pos.1)
|
||||
.map(|&folder_hash| (*idxa, *idxf) == (self.new_cursor_pos.0, folder_hash))
|
||||
.unwrap_or(false) =>
|
||||
{
|
||||
self.refresh_mailbox(context);
|
||||
self.set_dirty(true);
|
||||
}
|
||||
UIEvent::StartupCheck(ref f)
|
||||
if *f
|
||||
== context.accounts[self.cursor_pos.0].folders_order[self.new_cursor_pos.1] =>
|
||||
if context.accounts[self.new_cursor_pos.0]
|
||||
.folders_order
|
||||
.get(self.new_cursor_pos.1)
|
||||
.map(|&folder_hash| *f == folder_hash)
|
||||
.unwrap_or(false) =>
|
||||
{
|
||||
self.refresh_mailbox(context);
|
||||
self.set_dirty(true);
|
||||
|
|
|
@ -1104,19 +1104,21 @@ impl Component for PlainListing {
|
|||
}
|
||||
match *event {
|
||||
UIEvent::MailboxUpdate((ref idxa, ref idxf))
|
||||
if (*idxa, *idxf)
|
||||
== (
|
||||
self.new_cursor_pos.0,
|
||||
context.accounts[self.new_cursor_pos.0].folders_order
|
||||
[self.new_cursor_pos.1],
|
||||
) =>
|
||||
if context.accounts[self.new_cursor_pos.0]
|
||||
.folders_order
|
||||
.get(self.new_cursor_pos.1)
|
||||
.map(|&folder_hash| (*idxa, *idxf) == (self.new_cursor_pos.0, folder_hash))
|
||||
.unwrap_or(false) =>
|
||||
{
|
||||
self.refresh_mailbox(context);
|
||||
self.set_dirty(true);
|
||||
}
|
||||
UIEvent::StartupCheck(ref f)
|
||||
if *f
|
||||
== context.accounts[self.cursor_pos.0].folders_order[self.new_cursor_pos.1] =>
|
||||
if context.accounts[self.new_cursor_pos.0]
|
||||
.folders_order
|
||||
.get(self.new_cursor_pos.1)
|
||||
.map(|&folder_hash| *f == folder_hash)
|
||||
.unwrap_or(false) =>
|
||||
{
|
||||
self.refresh_mailbox(context);
|
||||
self.set_dirty(true);
|
||||
|
|
|
@ -264,7 +264,14 @@ impl ThreadListing {
|
|||
}
|
||||
self.cursor_pos.1 = self.new_cursor_pos.1;
|
||||
self.cursor_pos.0 = self.new_cursor_pos.0;
|
||||
let folder_hash = context.accounts[self.cursor_pos.0].folders_order[self.cursor_pos.1];
|
||||
let folder_hash = if let Some(h) = context.accounts[self.cursor_pos.0]
|
||||
.folders_order
|
||||
.get(self.cursor_pos.1)
|
||||
{
|
||||
*h
|
||||
} else {
|
||||
return;
|
||||
};
|
||||
|
||||
// Inform State that we changed the current folder view.
|
||||
context
|
||||
|
@ -620,20 +627,21 @@ impl Component for ThreadListing {
|
|||
self.view = None;
|
||||
}
|
||||
UIEvent::MailboxUpdate((ref idxa, ref idxf))
|
||||
if (*idxa, *idxf)
|
||||
== (
|
||||
self.new_cursor_pos.0,
|
||||
context.accounts[self.new_cursor_pos.0].folders_order
|
||||
[self.new_cursor_pos.1],
|
||||
) =>
|
||||
if context.accounts[self.new_cursor_pos.0]
|
||||
.folders_order
|
||||
.get(self.new_cursor_pos.1)
|
||||
.map(|&folder_hash| (*idxa, *idxf) == (self.new_cursor_pos.0, folder_hash))
|
||||
.unwrap_or(false) =>
|
||||
{
|
||||
self.refresh_mailbox(context);
|
||||
self.set_dirty(true);
|
||||
}
|
||||
UIEvent::StartupCheck(ref f)
|
||||
if *f
|
||||
== context.accounts[self.new_cursor_pos.0].folders_order
|
||||
[self.new_cursor_pos.1] =>
|
||||
if context.accounts[self.new_cursor_pos.0]
|
||||
.folders_order
|
||||
.get(self.new_cursor_pos.1)
|
||||
.map(|&folder_hash| *f == folder_hash)
|
||||
.unwrap_or(false) =>
|
||||
{
|
||||
self.refresh_mailbox(context);
|
||||
self.set_dirty(true);
|
||||
|
|
|
@ -634,15 +634,13 @@ impl ThreadView {
|
|||
let mailbox = &account[self.coordinates.1].unwrap();
|
||||
let threads = &account.collection.threads[&mailbox.folder.hash()];
|
||||
let thread_node = &threads.thread_nodes()[&threads.root_set(self.coordinates.2)];
|
||||
let i = if let Some(i) = thread_node.message() {
|
||||
i
|
||||
} else {
|
||||
let i = thread_node.message().unwrap_or_else(|| {
|
||||
let mut iter_ptr = thread_node.children()[0];
|
||||
while threads.thread_nodes()[&iter_ptr].message().is_none() {
|
||||
iter_ptr = threads.thread_nodes()[&iter_ptr].children()[0];
|
||||
}
|
||||
threads.thread_nodes()[&iter_ptr].message().unwrap()
|
||||
};
|
||||
});
|
||||
let envelope: EnvelopeRef = account.collection.get_env(i);
|
||||
|
||||
let (x, y) = write_string_to_grid(
|
||||
|
@ -726,15 +724,13 @@ impl ThreadView {
|
|||
let mailbox = &account[self.coordinates.1].unwrap();
|
||||
let threads = &account.collection.threads[&mailbox.folder.hash()];
|
||||
let thread_node = &threads.thread_nodes()[&threads.root_set(self.coordinates.2)];
|
||||
let i = if let Some(i) = thread_node.message() {
|
||||
i
|
||||
} else {
|
||||
let i = thread_node.message().unwrap_or_else(|| {
|
||||
let mut iter_ptr = thread_node.children()[0];
|
||||
while threads.thread_nodes()[&iter_ptr].message().is_none() {
|
||||
iter_ptr = threads.thread_nodes()[&iter_ptr].children()[0];
|
||||
}
|
||||
threads.thread_nodes()[&iter_ptr].message().unwrap()
|
||||
};
|
||||
});
|
||||
let envelope: EnvelopeRef = account.collection.get_env(i);
|
||||
|
||||
let (x, y) = write_string_to_grid(
|
||||
|
|
|
@ -75,9 +75,7 @@ pub fn create_temp_file(
|
|||
) -> File {
|
||||
let mut dir = std::env::temp_dir();
|
||||
|
||||
let path = if let Some(p) = path {
|
||||
p
|
||||
} else {
|
||||
let path = path.unwrap_or_else(|| {
|
||||
dir.push("meli");
|
||||
std::fs::DirBuilder::new()
|
||||
.recursive(true)
|
||||
|
@ -90,7 +88,7 @@ pub fn create_temp_file(
|
|||
dir.push(u.to_hyphenated().to_string());
|
||||
}
|
||||
&dir
|
||||
};
|
||||
});
|
||||
|
||||
let mut f = std::fs::File::create(path).unwrap();
|
||||
let metadata = f.metadata().unwrap();
|
||||
|
|
Loading…
Reference in New Issue