Browse Source

Fix some clippy lints

tags/v2
Manos Pitsidianakis 1 year ago
parent
commit
8c6c9806b5
Signed by: epilys GPG Key ID: 73627C2F690DF710
  1. 5
      config_macros.rs
  2. 6
      melib/src/backends.rs
  3. 1
      melib/src/backends/imap/cache.rs
  4. 4
      melib/src/backends/imap/connection.rs
  5. 4
      melib/src/backends/imap/operations.rs
  6. 10
      melib/src/backends/imap/protocol_parser.rs
  7. 49
      melib/src/backends/mbox.rs
  8. 2
      melib/src/conf.rs
  9. 26
      melib/src/email.rs
  10. 6
      melib/src/email/attachment_types.rs
  11. 67
      melib/src/email/attachments.rs
  12. 2
      melib/src/email/compose/mime.rs
  13. 8
      melib/src/email/parser.rs
  14. 4
      melib/src/error.rs
  15. 6
      melib/src/lib.rs
  16. 39
      melib/src/search.rs
  17. 4
      melib/src/text_processing/grapheme_clusters.rs
  18. 4
      melib/src/text_processing/line_break.rs
  19. 2
      melib/src/thread.rs

5
config_macros.rs

@ -58,7 +58,8 @@ use super::*;
'file_loop: for (filename, ident) in filenames {
println!("cargo:rerun-if-changed={}", filename);
let mut file = File::open(&filename).expect(&format!("Unable to open file `{}`", filename));
let mut file = File::open(&filename)
.unwrap_or_else(|err| panic!("Unable to open file `{}` {}", filename, err));
let mut src = String::new();
file.read_to_string(&mut src).expect("Unable to read file");
@ -148,7 +149,7 @@ use super::*;
}
}
};
output_string.extend(literal_struct.to_string().chars());
output_string.push_str(&literal_struct.to_string());
output_string.push_str("\n\n");
}
}

6
melib/src/backends.rs

@ -261,9 +261,9 @@ impl RefreshEvent {
}
#[derive(Clone)]
pub struct BackendEventConsumer(Arc<dyn Fn(AccountHash, BackendEvent) -> () + Send + Sync>);
pub struct BackendEventConsumer(Arc<dyn Fn(AccountHash, BackendEvent) + Send + Sync>);
impl BackendEventConsumer {
pub fn new(b: Arc<dyn Fn(AccountHash, BackendEvent) -> () + Send + Sync>) -> Self {
pub fn new(b: Arc<dyn Fn(AccountHash, BackendEvent) + Send + Sync>) -> Self {
BackendEventConsumer(b)
}
}
@ -275,7 +275,7 @@ impl fmt::Debug for BackendEventConsumer {
}
impl Deref for BackendEventConsumer {
type Target = dyn Fn(AccountHash, BackendEvent) -> () + Send + Sync;
type Target = dyn Fn(AccountHash, BackendEvent) + Send + Sync;
fn deref(&self) -> &Self::Target {
&(*self.0)

1
melib/src/backends/imap/cache.rs

@ -191,7 +191,6 @@ mod sqlite3_m {
row.get(2)?,
))
})?
.into_iter()
.collect::<std::result::Result<_, _>>()?;
let mut max_uid = 0;
let mut env_lck = self.uid_store.envelopes.lock().unwrap();

4
melib/src/backends/imap/connection.rs

@ -825,7 +825,7 @@ impl ImapConnection {
let mut nonexistent = "blurdybloop".to_string();
{
let mailboxes = self.uid_store.mailboxes.lock().await;
while mailboxes.values().any(|m| m.imap_path() == &nonexistent) {
while mailboxes.values().any(|m| m.imap_path() == nonexistent) {
nonexistent.push('p');
}
}
@ -905,7 +905,7 @@ impl ImapBlockingConnection {
}
pub fn err(&self) -> Option<&str> {
self.err.as_ref().map(String::as_str)
self.err.as_deref()
}
pub fn as_stream<'a>(&'a mut self) -> impl Future<Output = Option<Vec<u8>>> + 'a {

4
melib/src/backends/imap/operations.rs

@ -78,7 +78,7 @@ impl BackendOp for ImapOp {
debug!(
"fetch response is {} bytes and {} lines",
response.len(),
response.lines().collect::<Vec<&str>>().len()
response.lines().count()
);
let FetchResponse {
uid: _uid,
@ -129,7 +129,7 @@ impl BackendOp for ImapOp {
debug!(
"fetch response is {} bytes and {} lines",
response.len(),
response.lines().collect::<Vec<&str>>().len()
response.lines().count()
);
let v = protocol_parser::uid_fetch_flags_responses(response.as_bytes())
.map(|(_, v)| v)

10
melib/src/backends/imap/protocol_parser.rs

@ -211,7 +211,7 @@ impl std::fmt::Display for ResponseCode {
impl ResponseCode {
fn from(val: &str) -> ResponseCode {
use ResponseCode::*;
if !val.starts_with("[") {
if !val.starts_with('[') {
let msg = val.trim();
return Alert(msg.to_string());
}
@ -669,7 +669,7 @@ pub fn fetch_responses(mut input: &str) -> ImapParseResult<Vec<FetchResponse<'_>
if let Some(el_alert) = el_alert {
match &mut alert {
Some(Alert(ref mut alert)) => {
alert.extend(el_alert.0.chars());
alert.push_str(&el_alert.0);
}
a @ None => *a = Some(el_alert),
}
@ -1123,13 +1123,13 @@ pub fn flags(input: &str) -> IResult<&str, (Flag, Vec<String>)> {
let mut keywords = Vec::new();
let mut input = input;
while !input.starts_with(")") && !input.is_empty() {
if input.starts_with("\\") {
while !input.starts_with(')') && !input.is_empty() {
if input.starts_with('\\') {
input = &input[1..];
}
let mut match_end = 0;
while match_end < input.len() {
if input[match_end..].starts_with(" ") || input[match_end..].starts_with(")") {
if input[match_end..].starts_with(' ') || input[match_end..].starts_with(')') {
break;
}
match_end += 1;

49
melib/src/backends/mbox.rs

@ -307,7 +307,7 @@ impl MboxReader {
match self {
Self::MboxO => {
let next_offset: Option<(usize, usize)> = find_From__line!(input)
.and_then(|end| input.find(b"\n").and_then(|start| Some((start + 1, end))));
.and_then(|end| input.find(b"\n").map(|start| (start + 1, end)));
if let Some((start, len)) = next_offset {
match Envelope::from_bytes(&input[start..len], None) {
@ -363,33 +363,33 @@ impl MboxReader {
Ok(mut env) => {
let mut flags = Flag::empty();
if env.other_headers().contains_key("Status") {
if env.other_headers()["Status"].contains("F") {
if env.other_headers()["Status"].contains('F') {
flags.set(Flag::FLAGGED, true);
}
if env.other_headers()["Status"].contains("A") {
if env.other_headers()["Status"].contains('A') {
flags.set(Flag::REPLIED, true);
}
if env.other_headers()["Status"].contains("R") {
if env.other_headers()["Status"].contains('R') {
flags.set(Flag::SEEN, true);
}
if env.other_headers()["Status"].contains("D") {
if env.other_headers()["Status"].contains('D') {
flags.set(Flag::TRASHED, true);
}
}
if env.other_headers().contains_key("X-Status") {
if env.other_headers()["X-Status"].contains("F") {
if env.other_headers()["X-Status"].contains('F') {
flags.set(Flag::FLAGGED, true);
}
if env.other_headers()["X-Status"].contains("A") {
if env.other_headers()["X-Status"].contains('A') {
flags.set(Flag::REPLIED, true);
}
if env.other_headers()["X-Status"].contains("R") {
if env.other_headers()["X-Status"].contains('R') {
flags.set(Flag::SEEN, true);
}
if env.other_headers()["X-Status"].contains("D") {
if env.other_headers()["X-Status"].contains('D') {
flags.set(Flag::TRASHED, true);
}
if env.other_headers()["X-Status"].contains("T") {
if env.other_headers()["X-Status"].contains('T') {
flags.set(Flag::DRAFT, true);
}
}
@ -405,7 +405,7 @@ impl MboxReader {
}
Self::MboxRd => {
let next_offset: Option<(usize, usize)> = find_From__line!(input)
.and_then(|end| input.find(b"\n").and_then(|start| Some((start + 1, end))));
.and_then(|end| input.find(b"\n").map(|start| (start + 1, end)));
if let Some((start, len)) = next_offset {
match Envelope::from_bytes(&input[start..len], None) {
@ -535,33 +535,33 @@ impl MboxReader {
Ok(mut env) => {
let mut flags = Flag::empty();
if env.other_headers().contains_key("Status") {
if env.other_headers()["Status"].contains("F") {
if env.other_headers()["Status"].contains('F') {
flags.set(Flag::FLAGGED, true);
}
if env.other_headers()["Status"].contains("A") {
if env.other_headers()["Status"].contains('A') {
flags.set(Flag::REPLIED, true);
}
if env.other_headers()["Status"].contains("R") {
if env.other_headers()["Status"].contains('R') {
flags.set(Flag::SEEN, true);
}
if env.other_headers()["Status"].contains("D") {
if env.other_headers()["Status"].contains('D') {
flags.set(Flag::TRASHED, true);
}
}
if env.other_headers().contains_key("X-Status") {
if env.other_headers()["X-Status"].contains("F") {
if env.other_headers()["X-Status"].contains('F') {
flags.set(Flag::FLAGGED, true);
}
if env.other_headers()["X-Status"].contains("A") {
if env.other_headers()["X-Status"].contains('A') {
flags.set(Flag::REPLIED, true);
}
if env.other_headers()["X-Status"].contains("R") {
if env.other_headers()["X-Status"].contains('R') {
flags.set(Flag::SEEN, true);
}
if env.other_headers()["X-Status"].contains("D") {
if env.other_headers()["X-Status"].contains('D') {
flags.set(Flag::TRASHED, true);
}
if env.other_headers()["X-Status"].contains("T") {
if env.other_headers()["X-Status"].contains('T') {
flags.set(Flag::DRAFT, true);
}
}
@ -761,7 +761,7 @@ impl MailBackend for MboxType {
}
if done {
if payload.is_empty() {
return Ok(None);
Ok(None)
} else {
let mut mailbox_lock = self.mailboxes.lock().unwrap();
let contents = std::mem::replace(&mut self.contents, vec![]);
@ -927,12 +927,7 @@ impl MailBackend for MboxType {
}
}
DebouncedEvent::Rename(src, dest) => {
if mailboxes
.lock()
.unwrap()
.values()
.any(|f| &f.fs_path == &src)
{
if mailboxes.lock().unwrap().values().any(|f| f.fs_path == src) {
let mailbox_hash = get_path_hash!(&src);
(sender)(
account_hash,

2
melib/src/conf.rs

@ -104,7 +104,7 @@ impl Default for MailboxConf {
impl MailboxConf {
pub fn alias(&self) -> Option<&str> {
self.alias.as_ref().map(String::as_str)
self.alias.as_deref()
}
}

26
melib/src/email.rs

@ -249,32 +249,27 @@ impl Envelope {
let name: HeaderName = name.try_into()?;
if name == "to" {
let parse_result = parser::address::rfc2822address_list(value);
if parse_result.is_ok() {
let value = parse_result.unwrap().1;
if let Ok((_, value)) = parse_result {
self.set_to(value);
};
} else if name == "cc" {
let parse_result = parser::address::rfc2822address_list(value);
if parse_result.is_ok() {
let value = parse_result.unwrap().1;
if let Ok((_, value)) = parse_result {
self.set_cc(value);
};
} else if name == "bcc" {
let parse_result = parser::address::rfc2822address_list(value);
if parse_result.is_ok() {
let value = parse_result.unwrap().1;
if let Ok((_, value)) = parse_result {
self.set_bcc(value.to_vec());
};
} else if name == "from" {
let parse_result = parser::address::rfc2822address_list(value);
if parse_result.is_ok() {
let value = parse_result.unwrap().1;
if let Ok((_, value)) = parse_result {
self.set_from(value);
}
} else if name == "subject" {
let parse_result = parser::encodings::phrase(value.trim(), false);
if parse_result.is_ok() {
let value = parse_result.unwrap().1;
if let Ok((_, value)) = parse_result {
self.set_subject(value);
};
} else if name == "message-id" {
@ -282,8 +277,8 @@ impl Envelope {
} else if name == "references" {
{
let parse_result = parser::address::references(value);
if parse_result.is_ok() {
for v in parse_result.unwrap().1 {
if let Ok((_, value)) = parse_result {
for v in value {
self.push_references(v);
}
}
@ -294,8 +289,7 @@ impl Envelope {
in_reply_to = Some(value);
} else if name == "date" {
let parse_result = parser::encodings::phrase(value, false);
if parse_result.is_ok() {
let value = parse_result.unwrap().1;
if let Ok((_, value)) = parse_result {
self.set_date(value.as_slice());
} else {
self.set_date(value);
@ -510,7 +504,7 @@ impl Envelope {
pub fn in_reply_to(&self) -> Option<&MessageID> {
self.in_reply_to
.as_ref()
.or(self.references.as_ref().and_then(|r| r.refs.last()))
.or_else(|| self.references.as_ref().and_then(|r| r.refs.last()))
}
pub fn in_reply_to_display(&self) -> Option<Cow<str>> {
@ -563,7 +557,7 @@ impl Envelope {
while new_val
.chars()
.last()
.map(|c| char::is_control(c))
.map(char::is_control)
.unwrap_or(false)
{
new_val.pop();

6
melib/src/email/attachment_types.rs

@ -209,7 +209,7 @@ impl ContentType {
}
}
pub fn make_boundary(parts: &Vec<AttachmentBuilder>) -> String {
pub fn make_boundary(parts: &[AttachmentBuilder]) -> String {
use crate::email::compose::random::gen_boundary;
let mut boundary = "bzz_bzz__bzz__".to_string();
let mut random_boundary = gen_boundary();
@ -236,7 +236,7 @@ impl ContentType {
}
}
boundary.extend(random_boundary.chars());
boundary.push_str(&random_boundary);
/* rfc134
* "The only mandatory parameter for the multipart Content-Type is the boundary parameter,
* which consists of 1 to 70 characters from a set of characters known to be very robust
@ -253,7 +253,7 @@ impl ContentType {
}
}
pub fn parts(&self) -> Option<&Vec<Attachment>> {
pub fn parts(&self) -> Option<&[Attachment]> {
if let ContentType::Multipart { ref parts, .. } = self {
Some(parts)
} else {

67
melib/src/email/attachments.rs

@ -200,7 +200,7 @@ impl AttachmentBuilder {
if n.eq_ignore_ascii_case(b"name") {
if let Ok(v) = crate::email::parser::encodings::phrase(v.trim(), false)
.as_ref()
.and_then(|(_, r)| Ok(String::from_utf8_lossy(r).to_string()))
.map(|(_, r)| String::from_utf8_lossy(r).to_string())
{
name = Some(v);
} else {
@ -529,7 +529,7 @@ impl Attachment {
}
pub fn mime_type(&self) -> String {
format!("{}", self.content_type).to_string()
self.content_type.to_string()
}
pub fn attachments(&self) -> Vec<Attachment> {
let mut ret = Vec::new();
@ -599,37 +599,35 @@ impl Attachment {
pub fn into_raw(&self) -> String {
let mut ret = String::with_capacity(2 * self.raw.len());
fn into_raw_helper(a: &Attachment, ret: &mut String) {
ret.extend(
format!(
"Content-Transfer-Encoding: {}\n",
a.content_transfer_encoding
)
.chars(),
);
ret.push_str(&format!(
"Content-Transfer-Encoding: {}\n",
a.content_transfer_encoding
));
match &a.content_type {
ContentType::Text {
kind: _,
parameters,
charset,
} => {
ret.extend(
format!("Content-Type: {}; charset={}", a.content_type, charset).chars(),
);
ret.push_str(&format!(
"Content-Type: {}; charset={}",
a.content_type, charset
));
for (n, v) in parameters {
ret.push_str("; ");
ret.extend(String::from_utf8_lossy(n).chars());
ret.push_str(&String::from_utf8_lossy(n));
ret.push_str("=");
if v.contains(&b' ') {
ret.push_str("\"");
}
ret.extend(String::from_utf8_lossy(v).chars());
ret.push_str(&String::from_utf8_lossy(v));
if v.contains(&b' ') {
ret.push_str("\"");
}
}
ret.push_str("\n\n");
ret.extend(String::from_utf8_lossy(a.body()).chars());
ret.push_str(&String::from_utf8_lossy(a.body()));
}
ContentType::Multipart {
boundary,
@ -637,42 +635,41 @@ impl Attachment {
parts,
} => {
let boundary = String::from_utf8_lossy(boundary);
ret.extend(format!("Content-Type: {}; boundary={}", kind, boundary).chars());
ret.push_str(&format!("Content-Type: {}; boundary={}", kind, boundary));
if *kind == MultipartType::Signed {
ret.extend(
"; micalg=pgp-sha512; protocol=\"application/pgp-signature\"".chars(),
);
ret.push_str("; micalg=pgp-sha512; protocol=\"application/pgp-signature\"");
}
ret.push('\n');
let boundary_start = format!("\n--{}\n", boundary);
for p in parts {
ret.extend(boundary_start.chars());
ret.push_str(&boundary_start);
into_raw_helper(p, ret);
}
ret.extend(format!("--{}--\n\n", boundary).chars());
ret.push_str(&format!("--{}--\n\n", boundary));
}
ContentType::MessageRfc822 => {
ret.extend(format!("Content-Type: {}\n\n", a.content_type).chars());
ret.extend(String::from_utf8_lossy(a.body()).chars());
ret.push_str(&format!("Content-Type: {}\n\n", a.content_type));
ret.push_str(&String::from_utf8_lossy(a.body()));
}
ContentType::PGPSignature => {
ret.extend(format!("Content-Type: {}\n\n", a.content_type).chars());
ret.extend(String::from_utf8_lossy(a.body()).chars());
ret.push_str(&format!("Content-Type: {}\n\n", a.content_type));
ret.push_str(&String::from_utf8_lossy(a.body()));
}
ContentType::OctetStream { ref name } => {
if let Some(name) = name {
ret.extend(
format!("Content-Type: {}; name={}\n\n", a.content_type, name).chars(),
);
ret.push_str(&format!(
"Content-Type: {}; name={}\n\n",
a.content_type, name
));
} else {
ret.extend(format!("Content-Type: {}\n\n", a.content_type).chars());
ret.push_str(&format!("Content-Type: {}\n\n", a.content_type));
}
ret.push_str(&BASE64_MIME.encode(a.body()).trim());
}
_ => {
ret.extend(format!("Content-Type: {}\n\n", a.content_type).chars());
ret.extend(String::from_utf8_lossy(a.body()).chars());
ret.push_str(&format!("Content-Type: {}\n\n", a.content_type));
ret.push_str(&String::from_utf8_lossy(a.body()));
}
}
}
@ -737,11 +734,9 @@ fn decode_rec_helper<'a>(a: &'a Attachment, filter: &mut Option<Filter<'a>>) ->
match a.content_type {
ContentType::Other { .. } => Vec::new(),
ContentType::Text { .. } => decode_helper(a, filter),
ContentType::OctetStream { ref name } => name
.clone()
.unwrap_or_else(|| a.mime_type())
.to_string()
.into_bytes(),
ContentType::OctetStream { ref name } => {
name.clone().unwrap_or_else(|| a.mime_type()).into_bytes()
}
ContentType::PGPSignature => Vec::new(),
ContentType::MessageRfc822 => {
let temp = decode_rfc822(a.body());

2
melib/src/email/compose/mime.rs

@ -41,7 +41,7 @@ pub fn encode_header(value: &str) -> String {
*
* Whitespaces inside encoded tokens must be greedily taken,
* instead of splitting each non-ascii word into separate encoded tokens. */
if !g.split_whitespace().next().is_none() {
if g.split_whitespace().next().is_some() {
ret.push_str(&format!(
"=?UTF-8?B?{}?=",
BASE64_MIME

8
melib/src/email/parser.rs

@ -417,7 +417,7 @@ pub mod headers {
));
}
let mut ptr = 0;
let mut name: &[u8] = &input[0..0];
let mut name: &[u8] = &[];
let mut has_colon = false;
/* field-name = 1*<any CHAR, excluding CTLs, SPACE, and ":"> */
for (i, x) in input.iter().enumerate() {
@ -573,7 +573,7 @@ pub mod headers {
));
}
let mut ptr = 0;
let mut name: &[u8] = &input[0..0];
let mut name: &[u8] = &[];
/* field-name = 1*<any CHAR, excluding CTLs, SPACE, and ":"> */
for (i, x) in input.iter().enumerate() {
if *x == b':' {
@ -635,7 +635,7 @@ pub mod headers {
pub fn headers_raw(input: &[u8]) -> IResult<&[u8], &[u8]> {
if input.is_empty() {
return Err(nom::Err::Error(
(input, format!("headers_raw(): input is empty",)).into(),
(input, "headers_raw(): input is empty").into(),
));
}
for i in 0..input.len() {
@ -1507,7 +1507,7 @@ pub mod address {
{
move |i: I| {
let mut res = SmallVec::new();
let mut i = i.clone();
let mut i = i;
// Parse the first element
match f(i.clone()) {

4
melib/src/error.rs

@ -158,11 +158,11 @@ impl fmt::Display for MeliError {
if let Some(summary) = self.summary.as_ref() {
writeln!(f, "Summary: {}", summary)?;
}
let ret = write!(f, "{}", self.details)?;
write!(f, "{}", self.details)?;
if let Some(source) = self.source.as_ref() {
write!(f, "\nCaused by: {}", source)?;
}
Ok(ret)
Ok(())
}
}

6
melib/src/lib.rs

@ -168,16 +168,16 @@ pub mod shellexpand {
let c_to_str = c.as_os_str().to_str();
match c_to_str {
Some("~") => {
if let Some(home_dir) = std::env::var("HOME").ok() {
if let Ok(home_dir) = std::env::var("HOME") {
ret.push(home_dir)
} else {
return PathBuf::new();
}
}
Some(var) if var.starts_with("$") => {
Some(var) if var.starts_with('$') => {
let env_name = var.split_at(1).1;
if env_name.chars().all(char::is_uppercase) {
ret.push(std::env::var(env_name).unwrap_or(String::new()));
ret.push(std::env::var(env_name).unwrap_or_default());
} else {
ret.push(c);
}

39
melib/src/search.rs

@ -109,7 +109,7 @@ pub mod query_parser {
whitespace_wrap(match_literal("subject:")),
whitespace_wrap(literal()),
)
.map(|term| Query::Subject(term))
.map(Query::Subject)
}
fn from<'a>() -> impl Parser<'a, Query> {
@ -117,7 +117,7 @@ pub mod query_parser {
whitespace_wrap(match_literal("from:")),
whitespace_wrap(literal()),
)
.map(|term| Query::From(term))
.map(Query::From)
}
fn to<'a>() -> impl Parser<'a, Query> {
@ -125,7 +125,7 @@ pub mod query_parser {
whitespace_wrap(match_literal("to:")),
whitespace_wrap(literal()),
)
.map(|term| Query::To(term))
.map(Query::To)
}
fn cc<'a>() -> impl Parser<'a, Query> {
@ -133,7 +133,7 @@ pub mod query_parser {
whitespace_wrap(match_literal("cc:")),
whitespace_wrap(literal()),
)
.map(|term| Query::Cc(term))
.map(Query::Cc)
}
fn bcc<'a>() -> impl Parser<'a, Query> {
@ -141,7 +141,7 @@ pub mod query_parser {
whitespace_wrap(match_literal("bcc:")),
whitespace_wrap(literal()),
)
.map(|term| Query::Bcc(term))
.map(Query::Bcc)
}
fn or<'a>() -> impl Parser<'a, Query> {
@ -212,14 +212,14 @@ pub mod query_parser {
})
.and_then(|(rest, flags_list)| {
if let Ok(r) = flags_list
.split(",")
.split(',')
.map(|t| {
either(quoted_string(), string())
.parse_complete(t)
.map(|(_, r)| r)
})
.collect::<std::result::Result<Vec<String>, &str>>()
.map(|v| Flags(v))
.map(Flags)
{
Ok((rest, r))
} else {
@ -245,13 +245,13 @@ pub mod query_parser {
move |input| {
let (rest, query_a): (&'a str, Query) = if let Ok(q) = parentheses_query()
.parse(input)
.or(from().parse(input))
.or(to().parse(input))
.or(cc().parse(input))
.or(bcc().parse(input))
.or(subject().parse(input))
.or(flags().parse(input))
.or(has_attachment().parse(input))
.or_else(|_| from().parse(input))
.or_else(|_| to().parse(input))
.or_else(|_| cc().parse(input))
.or_else(|_| bcc().parse(input))
.or_else(|_| subject().parse(input))
.or_else(|_| flags().parse(input))
.or_else(|_| has_attachment().parse(input))
{
Ok(q)
} else if let Ok((rest, query_a)) = not().parse(input) {
@ -399,11 +399,10 @@ impl<'de> Deserialize<'de> for Query {
D: Deserializer<'de>,
{
let s = <String>::deserialize(deserializer)?;
let _q = query().parse(&s);
if let Some(q) = _q.ok() {
Ok(q.1)
} else {
Err(de::Error::custom("invalid query value"))
}
let ret = query()
.parse(&s)
.map(|(_, q)| q)
.map_err(|err| de::Error::custom(format!("invalid query value: {}", err)));
ret
}
}

4
melib/src/text_processing/grapheme_clusters.rs

@ -98,7 +98,7 @@ impl<'s> Iterator for WordBreakIter<'s> {
}
self.input = self.input.trim_start_matches(|c| c == ' ');
if self.input.starts_with('\n') {
let ret = &self.input[0..0];
let ret = "";
self.input = &self.input[1..];
return Some(ret);
}
@ -129,7 +129,7 @@ impl<'s> Iterator for WordBreakIter<'s> {
} else {
/* graphemes.len() < width */
let ret = self.input;
self.input = &self.input[0..0];
self.input = "";
Some(ret)
}
}

4
melib/src/text_processing/line_break.rs

@ -776,7 +776,7 @@ mod alg {
minima: &mut Vec<usize>,
breaks: &mut Vec<usize>,
width: usize,
offsets: &Vec<usize>,
offsets: &[usize],
) {
let mut stack = Vec::new();
let mut i = 0;
@ -846,7 +846,7 @@ mod alg {
prev = b.0;
}
if &text[prev..] != "\n" {
words.push(text[prev..].trim_end_matches("\n"));
words.push(text[prev..].trim_end_matches('\n'));
}
}
let count = words.len();

2
melib/src/thread.rs

@ -686,7 +686,7 @@ impl Threads {
None
},
)
.unwrap_or_else(|| ThreadNodeHash::new());
.unwrap_or_else(ThreadNodeHash::new);
{
let mut node = self.thread_nodes.entry(new_id).or_default();
node.message = Some(env_hash);

Loading…
Cancel
Save