Run clippy for 2018 edition
parent
ee4462881e
commit
067a8e5c81
|
@ -217,8 +217,8 @@ impl MailBackend for MaildirType {
|
|||
}
|
||||
}
|
||||
/* Update */
|
||||
DebouncedEvent::NoticeWrite(mut pathbuf)
|
||||
| DebouncedEvent::Write(mut pathbuf) => {
|
||||
DebouncedEvent::NoticeWrite(pathbuf)
|
||||
| DebouncedEvent::Write(pathbuf) => {
|
||||
let folder_hash = get_path_hash!(pathbuf);
|
||||
let mut hash_indexes_lock = hash_indexes.lock().unwrap();
|
||||
let index_lock = &mut hash_indexes_lock.entry(folder_hash).or_default();
|
||||
|
@ -258,8 +258,8 @@ impl MailBackend for MaildirType {
|
|||
let op = Box::new(MaildirOp::new(new_hash, hash_indexes.clone(), folder_hash));
|
||||
if let Some(env) = Envelope::from_token(op, new_hash) {
|
||||
if cfg!(feature = "debug_log") {
|
||||
eprintln!("{}\t{}", new_hash, pathbuf.display());
|
||||
}
|
||||
eprintln!("{}\t{}", new_hash, pathbuf.display());
|
||||
}
|
||||
index_lock.insert(new_hash, pathbuf);
|
||||
|
||||
/* Send Write notice */
|
||||
|
@ -268,16 +268,14 @@ eprintln!("{}\t{}", new_hash, pathbuf.display());
|
|||
hash: folder_hash,
|
||||
kind: Update(old_hash, Box::new(env)),
|
||||
});
|
||||
} else {
|
||||
if cfg!(feature = "debug_log") {
|
||||
eprintln!("DEBUG: hash {}, path: {} couldn't be parsed in `add_path_to_index`", new_hash, pathbuf.as_path().display());
|
||||
}
|
||||
} else if cfg!(feature = "debug_log") {
|
||||
eprintln!("DEBUG: hash {}, path: {} couldn't be parsed in `add_path_to_index`", new_hash, pathbuf.as_path().display());
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Remove */
|
||||
DebouncedEvent::NoticeRemove(mut pathbuf)
|
||||
| DebouncedEvent::Remove(mut pathbuf) => {
|
||||
DebouncedEvent::NoticeRemove(pathbuf)
|
||||
| DebouncedEvent::Remove(pathbuf) => {
|
||||
let folder_hash = get_path_hash!(pathbuf);
|
||||
let mut hash_indexes_lock = hash_indexes.lock().unwrap();
|
||||
let index_lock = hash_indexes_lock.entry(folder_hash).or_default();
|
||||
|
@ -296,7 +294,7 @@ eprintln!("DEBUG: hash {}, path: {} couldn't be parsed in `add_path_to_index`",
|
|||
});
|
||||
}
|
||||
/* Envelope hasn't changed, so handle this here */
|
||||
DebouncedEvent::Rename(mut src, mut dest) => {
|
||||
DebouncedEvent::Rename(src, dest) => {
|
||||
let folder_hash = get_path_hash!(src);
|
||||
let old_hash: EnvelopeHash = get_file_hash(src.as_path());
|
||||
let new_hash: EnvelopeHash = get_file_hash(dest.as_path());
|
||||
|
@ -517,7 +515,7 @@ impl MaildirType {
|
|||
};
|
||||
for chunk in files.chunks(chunk_size) {
|
||||
let cache_dir = cache_dir.clone();
|
||||
let mut tx = tx.clone();
|
||||
let tx = tx.clone();
|
||||
let map = map.clone();
|
||||
let root_path = root_path.clone();
|
||||
let s = scope.builder().name(name.clone()).spawn(move || {
|
||||
|
@ -548,7 +546,7 @@ impl MaildirType {
|
|||
let result: result::Result<Envelope, _> = bincode::deserialize_from(reader);
|
||||
if let Ok(env) = result {
|
||||
let mut map = map.lock().unwrap();
|
||||
let mut map = map.entry(folder_hash).or_default();;
|
||||
let map = map.entry(folder_hash).or_default();;
|
||||
let hash = env.hash();
|
||||
map.insert(hash, file.clone());
|
||||
local_r.push(env);
|
||||
|
@ -558,12 +556,12 @@ impl MaildirType {
|
|||
let hash = get_file_hash(file);
|
||||
{
|
||||
let mut map = map.lock().unwrap();
|
||||
let mut map = map.entry(folder_hash).or_default();
|
||||
let map = map.entry(folder_hash).or_default();
|
||||
(*map).insert(hash, PathBuf::from(file));
|
||||
}
|
||||
let op =
|
||||
Box::new(MaildirOp::new(hash, map.clone(), folder_hash));
|
||||
if let Some(mut e) = Envelope::from_token(op, hash)
|
||||
if let Some(e) = Envelope::from_token(op, hash)
|
||||
{
|
||||
if let Ok(cached) =
|
||||
cache_dir.place_cache_file(file_name)
|
||||
|
|
|
@ -544,7 +544,7 @@ impl Envelope {
|
|||
eprintln!("error in parsing mail\n");
|
||||
}
|
||||
let error_msg = b"Mail cannot be shown because of errors.";
|
||||
let mut builder = AttachmentBuilder::new(error_msg);
|
||||
let builder = AttachmentBuilder::new(error_msg);
|
||||
return builder.build();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -93,27 +93,29 @@ macro_rules! make {
|
|||
}
|
||||
|
||||
/* Strip common prefixes from subjects */
|
||||
trait SubjectPrefix<'a> {
|
||||
fn strip_prefixes(&'a mut self) -> bool;
|
||||
trait SubjectPrefix {
|
||||
fn is_a_reply(&self) -> bool;
|
||||
fn strip_prefixes(&mut self);
|
||||
}
|
||||
|
||||
impl<'a> SubjectPrefix<'a> for &'a [u8] {
|
||||
fn strip_prefixes(&'a mut self) -> bool {
|
||||
let mut ret: bool = false;
|
||||
impl SubjectPrefix for &[u8] {
|
||||
fn is_a_reply(&self) -> bool {
|
||||
self.starts_with(b"RE: ")
|
||||
|| self.starts_with(b"Re: ")
|
||||
|| self.starts_with(b"FW: ")
|
||||
|| self.starts_with(b"Fw: ")
|
||||
}
|
||||
|
||||
fn strip_prefixes(&mut self) {
|
||||
let result = {
|
||||
let mut slice = self.trim();
|
||||
let mut end_prefix_idx = 0;
|
||||
loop {
|
||||
if slice.starts_with(b"RE: ")
|
||||
|| slice.starts_with(b"Re: ")
|
||||
|| slice.starts_with(b"FW: ")
|
||||
|| slice.starts_with(b"Fw: ")
|
||||
{
|
||||
if end_prefix_idx == 0 {
|
||||
ret = true;
|
||||
}
|
||||
slice = &slice[3..];
|
||||
end_prefix_idx += 3;
|
||||
continue;
|
||||
}
|
||||
if slice.starts_with(b"FWD: ")
|
||||
|
@ -121,24 +123,21 @@ impl<'a> SubjectPrefix<'a> for &'a [u8] {
|
|||
|| slice.starts_with(b"fwd: ")
|
||||
{
|
||||
slice = &slice[4..];
|
||||
end_prefix_idx += 4;
|
||||
continue;
|
||||
}
|
||||
if slice.starts_with(b" ") || slice.starts_with(b"\t") || slice.starts_with(b"\r") {
|
||||
//FIXME just trim whitespace
|
||||
slice = &slice[1..];
|
||||
end_prefix_idx += 1;
|
||||
continue;
|
||||
}
|
||||
if slice.starts_with(b"[")
|
||||
&& !(slice.starts_with(b"[PATCH") || slice.starts_with(b"[RFC"))
|
||||
{
|
||||
if let Some(pos) = slice.find(b"]") {
|
||||
end_prefix_idx += pos;
|
||||
slice = &slice[pos..];
|
||||
continue;
|
||||
}
|
||||
slice = &slice[1..];
|
||||
end_prefix_idx += 1;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
@ -146,7 +145,6 @@ impl<'a> SubjectPrefix<'a> for &'a [u8] {
|
|||
slice
|
||||
};
|
||||
*self = result;
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -576,38 +574,24 @@ impl Threads {
|
|||
|
||||
t.create_root_set(collection);
|
||||
t.build_collection(collection);
|
||||
for (i, _t) in t.thread_nodes.iter().enumerate() {
|
||||
if cfg!(feature = "debug_log") {
|
||||
if cfg!(feature = "debug_log") {
|
||||
for (i, _t) in t.thread_nodes.iter().enumerate() {
|
||||
eprintln!("Thread #{}, children {}", i, _t.children.len());
|
||||
}
|
||||
if !_t.children.is_empty() {
|
||||
if cfg!(feature = "debug_log") {
|
||||
if !_t.children.is_empty() {
|
||||
eprintln!("{:?}", _t.children);
|
||||
}
|
||||
}
|
||||
if let Some(m) = _t.message {
|
||||
if cfg!(feature = "debug_log") {
|
||||
if let Some(m) = _t.message {
|
||||
eprintln!("\tmessage: {}", collection[&m].subject());
|
||||
}
|
||||
} else {
|
||||
if cfg!(feature = "debug_log") {
|
||||
} else {
|
||||
eprintln!("\tNo message");
|
||||
}
|
||||
}
|
||||
}
|
||||
if cfg!(feature = "debug_log") {
|
||||
eprintln!("\n");
|
||||
}
|
||||
for (i, _t) in t.tree.borrow().iter().enumerate() {
|
||||
if cfg!(feature = "debug_log") {
|
||||
for (i, _t) in t.tree.borrow().iter().enumerate() {
|
||||
eprintln!("Tree #{} id {}, children {}", i, _t.id, _t.children.len());
|
||||
}
|
||||
if let Some(m) = t.thread_nodes[_t.id].message {
|
||||
if cfg!(feature = "debug_log") {
|
||||
if let Some(m) = t.thread_nodes[_t.id].message {
|
||||
eprintln!("\tmessage: {}", collection[&m].subject());
|
||||
}
|
||||
} else {
|
||||
if cfg!(feature = "debug_log") {
|
||||
} else {
|
||||
eprintln!("\tNo message");
|
||||
}
|
||||
}
|
||||
|
@ -621,7 +605,7 @@ impl Threads {
|
|||
let mut root_set: Vec<usize> = Vec::with_capacity(collection.len());
|
||||
|
||||
/* Find the root set */
|
||||
'root_set: for v in self.message_ids.values() {
|
||||
for v in self.message_ids.values() {
|
||||
if self.thread_nodes[*v].parent.is_none() {
|
||||
root_set.push(*v);
|
||||
}
|
||||
|
@ -652,7 +636,7 @@ impl Threads {
|
|||
/* "If there is no message in the Container, then the Container will have at least
|
||||
* one child Container, and that Container will have a message. Use the subject of
|
||||
* that message instead." */
|
||||
let mut msg_idx = self.thread_nodes[self.thread_nodes[r].children[0]]
|
||||
let msg_idx = self.thread_nodes[self.thread_nodes[r].children[0]]
|
||||
.message
|
||||
.unwrap();
|
||||
let envelope = &collection[&msg_idx];
|
||||
|
@ -663,7 +647,8 @@ impl Threads {
|
|||
/* References of this envelope can be empty but if the subject contains a ``Re:``
|
||||
* prefix, it's a reply */
|
||||
let mut stripped_subj = subject.to_mut().as_bytes();
|
||||
is_re |= stripped_subj.strip_prefixes();
|
||||
is_re |= stripped_subj.is_a_reply();
|
||||
stripped_subj.strip_prefixes();
|
||||
|
||||
if stripped_subj.is_empty() {
|
||||
continue;
|
||||
|
@ -711,7 +696,8 @@ impl Threads {
|
|||
};
|
||||
|
||||
let mut subject = subject.to_mut().as_bytes();
|
||||
is_re |= subject.strip_prefixes();
|
||||
is_re |= subject.is_a_reply();
|
||||
subject.strip_prefixes();
|
||||
if subject.is_empty() {
|
||||
continue;
|
||||
}
|
||||
|
@ -975,11 +961,7 @@ impl Threads {
|
|||
let mut stack = Vec::with_capacity(32);
|
||||
|
||||
let no_parent: bool = if let Some(node) = self.thread_nodes.get(node_idx) {
|
||||
if node.parent.is_none() {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
node.parent.is_none()
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
@ -1058,7 +1040,7 @@ impl Threads {
|
|||
|
||||
fn inner_subsort_by(&self, subsort: (SortField, SortOrder), collection: &Envelopes) {
|
||||
let tree = &mut self.tree.borrow_mut();
|
||||
for mut t in tree.iter_mut() {
|
||||
for t in tree.iter_mut() {
|
||||
t.children.sort_by(|a, b| match subsort {
|
||||
(SortField::Date, SortOrder::Desc) => {
|
||||
let a = &self.thread_nodes[a.id];
|
||||
|
@ -1316,10 +1298,10 @@ fn node_build(
|
|||
*/
|
||||
let mut subject = collection[&hash].subject();
|
||||
let mut subject = subject.to_mut().as_bytes();
|
||||
let subject = subject.strip_prefixes();
|
||||
subject.strip_prefixes();
|
||||
let mut parent_subject = collection[&parent_hash].subject();
|
||||
let mut parent_subject = parent_subject.to_mut().as_bytes();
|
||||
let parent_subject = parent_subject.strip_prefixes();
|
||||
parent_subject.strip_prefixes();
|
||||
if subject == parent_subject {
|
||||
thread_nodes[idx].show_subject = false;
|
||||
}
|
||||
|
|
|
@ -93,10 +93,8 @@ impl AccountMenu {
|
|||
a: &AccountMenuEntry,
|
||||
context: &mut Context,
|
||||
) -> usize {
|
||||
if !is_valid_area!(area) {
|
||||
if cfg!(feature = "debug_log") {
|
||||
eprintln!("BUG: invalid area in print_account");
|
||||
}
|
||||
if cfg!(feature = "debug_log") && !is_valid_area!(area) {
|
||||
eprintln!("BUG: invalid area in print_account");
|
||||
}
|
||||
let upper_left = upper_left!(area);
|
||||
let bottom_right = bottom_right!(area);
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
use super::*;
|
||||
use fnv::FnvHashMap;
|
||||
|
||||
type AutoCompleteFn = Box<Fn(&Context, &str) -> Vec<String> + Send>;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
enum FormFocus {
|
||||
Fields,
|
||||
|
@ -17,10 +19,7 @@ impl Default for FormFocus {
|
|||
}
|
||||
|
||||
pub enum Field {
|
||||
Text(
|
||||
UText,
|
||||
Option<(Box<Fn(&Context, &str) -> Vec<String> + Send>, AutoComplete)>,
|
||||
),
|
||||
Text(UText, Option<(AutoCompleteFn, AutoComplete)>),
|
||||
Choice(Vec<String>, Cursor),
|
||||
}
|
||||
|
||||
|
@ -169,15 +168,14 @@ impl Component for Field {
|
|||
}
|
||||
}
|
||||
}
|
||||
UIEventType::InsertInput(Key::Backspace) => match self {
|
||||
Text(ref mut s, auto_complete) => {
|
||||
UIEventType::InsertInput(Key::Backspace) => {
|
||||
if let Text(ref mut s, auto_complete) = self {
|
||||
s.backspace();
|
||||
if let Some(ac) = auto_complete.as_mut() {
|
||||
ac.1.set_suggestions(Vec::new());
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
}
|
||||
_ => {
|
||||
return false;
|
||||
}
|
||||
|
@ -251,14 +249,7 @@ impl FormWidget {
|
|||
self.layout.push(value.0.clone());
|
||||
self.fields.insert(value.0, Choice(value.1, 0));
|
||||
}
|
||||
pub fn push_cl(
|
||||
&mut self,
|
||||
value: (
|
||||
String,
|
||||
String,
|
||||
Box<Fn(&Context, &str) -> Vec<String> + Send>,
|
||||
),
|
||||
) {
|
||||
pub fn push_cl(&mut self, value: (String, String, AutoCompleteFn)) {
|
||||
self.field_name_max_length = std::cmp::max(self.field_name_max_length, value.0.len());
|
||||
self.layout.push(value.0.clone());
|
||||
self.fields.insert(
|
||||
|
|
|
@ -749,7 +749,7 @@ pub fn word_break_string(mut s: &str, width: usize) -> Vec<&str> {
|
|||
break;
|
||||
}
|
||||
s = s.trim_start_matches(|c| c == ' ');
|
||||
if s.starts_with("\n") {
|
||||
if s.starts_with('\n') {
|
||||
ret.push(&s[0..0]);
|
||||
s = &s["\n".len()..];
|
||||
continue;
|
||||
|
|
|
@ -19,11 +19,11 @@ pub trait Graphemes: UnicodeSegmentation + CodePointsIter {
|
|||
UnicodeSegmentation::grapheme_indices(self, true).collect::<Vec<(usize, &str)>>()
|
||||
}
|
||||
|
||||
fn next_grapheme<'a>(&'a self) -> Option<(usize, &'a str)> {
|
||||
fn next_grapheme(&self) -> Option<(usize, &str)> {
|
||||
UnicodeSegmentation::grapheme_indices(self, true).next()
|
||||
}
|
||||
|
||||
fn last_grapheme<'a>(&'a self) -> Option<(usize, &'a str)> {
|
||||
fn last_grapheme(&self) -> Option<(usize, &str)> {
|
||||
UnicodeSegmentation::grapheme_indices(self, true).next_back()
|
||||
}
|
||||
|
||||
|
|
|
@ -46,29 +46,29 @@ impl<'a> Iterator for CodePointsIterator<'a> {
|
|||
}
|
||||
/* Input is UTF-8 valid strings, guaranteed by Rust's std */
|
||||
if self.rest[0] & 0b1000_0000 == 0x0 {
|
||||
let ret: WChar = self.rest[0] as WChar;
|
||||
let ret: WChar = WChar::from(self.rest[0]);
|
||||
self.rest = &self.rest[1..];
|
||||
return Some(ret);
|
||||
}
|
||||
if self.rest[0] & 0b1110_0000 == 0b1100_0000 {
|
||||
let ret: WChar = (self.rest[0] as WChar & 0b0001_1111).rotate_left(6)
|
||||
+ (self.rest[1] as WChar & 0b0111_1111);
|
||||
let ret: WChar = (WChar::from(self.rest[0]) & 0b0001_1111).rotate_left(6)
|
||||
+ (WChar::from(self.rest[1]) & 0b0111_1111);
|
||||
self.rest = &self.rest[2..];
|
||||
return Some(ret);
|
||||
}
|
||||
|
||||
if self.rest[0] & 0b1111_0000 == 0b1110_0000 {
|
||||
let ret: WChar = (self.rest[0] as WChar & 0b0000_0111).rotate_left(12)
|
||||
+ (self.rest[1] as WChar & 0b0011_1111).rotate_left(6)
|
||||
+ (self.rest[2] as WChar & 0b0011_1111);
|
||||
let ret: WChar = (WChar::from(self.rest[0]) & 0b0000_0111).rotate_left(12)
|
||||
+ (WChar::from(self.rest[1]) & 0b0011_1111).rotate_left(6)
|
||||
+ (WChar::from(self.rest[2]) & 0b0011_1111);
|
||||
self.rest = &self.rest[3..];
|
||||
return Some(ret);
|
||||
}
|
||||
|
||||
let ret: WChar = (self.rest[0] as WChar & 0b0000_0111).rotate_left(18)
|
||||
+ (self.rest[1] as WChar & 0b0011_1111).rotate_left(12)
|
||||
+ (self.rest[2] as WChar & 0b0011_1111).rotate_left(6)
|
||||
+ (self.rest[3] as WChar & 0b0011_1111);
|
||||
let ret: WChar = (WChar::from(self.rest[0]) & 0b0000_0111).rotate_left(18)
|
||||
+ (WChar::from(self.rest[1]) & 0b0011_1111).rotate_left(12)
|
||||
+ (WChar::from(self.rest[2]) & 0b0011_1111).rotate_left(6)
|
||||
+ (WChar::from(self.rest[3]) & 0b0011_1111);
|
||||
self.rest = &self.rest[4..];
|
||||
Some(ret)
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ fn bisearch(ucs: WChar, table: &'static [Interval]) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
false
|
||||
}
|
||||
|
||||
/* The following functions define the column width of an ISO 10646
|
||||
|
@ -266,7 +266,7 @@ pub fn wcwidth(ucs: WChar) -> Option<usize> {
|
|||
|
||||
/* if we arrive here, ucs is not a combining or C0/C1 control character */
|
||||
|
||||
return Some(
|
||||
Some(
|
||||
1 + big_if_true!(
|
||||
ucs >= 0x1100
|
||||
&& (ucs <= 0x115f || /* Hangul Jamo init. consonants */
|
||||
|
@ -279,7 +279,7 @@ pub fn wcwidth(ucs: WChar) -> Option<usize> {
|
|||
(ucs >= 0xffe0 && ucs <= 0xffe6) ||
|
||||
(ucs >= 0x20000 && ucs <= 0x2ffff))
|
||||
),
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
fn wcswidth(mut pwcs: WChar, mut n: usize) -> Option<usize> {
|
||||
|
@ -296,7 +296,7 @@ fn wcswidth(mut pwcs: WChar, mut n: usize) -> Option<usize> {
|
|||
n -= 1;
|
||||
}
|
||||
|
||||
return Some(width);
|
||||
Some(width)
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -476,7 +476,7 @@ pub fn wcwidth_cjk(ucs: WChar) -> Option<usize> {
|
|||
return Some(2);
|
||||
}
|
||||
|
||||
return wcwidth(ucs);
|
||||
wcwidth(ucs)
|
||||
}
|
||||
|
||||
fn wcswidth_cjk(mut pwcs: WChar, mut n: WChar) -> Option<usize> {
|
||||
|
@ -493,5 +493,5 @@ fn wcswidth_cjk(mut pwcs: WChar, mut n: WChar) -> Option<usize> {
|
|||
n -= 1;
|
||||
}
|
||||
|
||||
return Some(width);
|
||||
Some(width)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue