mirror of
https://github.com/chatmail/core.git
synced 2026-05-19 06:46:32 +03:00
refactor: forbid clippy::string_slice
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
clippy::cloned_instead_of_copied
|
clippy::cloned_instead_of_copied
|
||||||
)]
|
)]
|
||||||
#![cfg_attr(not(test), forbid(clippy::indexing_slicing))]
|
#![cfg_attr(not(test), forbid(clippy::indexing_slicing))]
|
||||||
|
#![cfg_attr(not(test), forbid(clippy::string_slice))]
|
||||||
#![allow(
|
#![allow(
|
||||||
clippy::match_bool,
|
clippy::match_bool,
|
||||||
clippy::mixed_read_write_in_expression,
|
clippy::mixed_read_write_in_expression,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#![recursion_limit = "256"]
|
#![recursion_limit = "256"]
|
||||||
#![cfg_attr(not(test), forbid(clippy::indexing_slicing))]
|
#![cfg_attr(not(test), forbid(clippy::indexing_slicing))]
|
||||||
|
#![cfg_attr(not(test), forbid(clippy::string_slice))]
|
||||||
pub mod api;
|
pub mod api;
|
||||||
pub use yerpc;
|
pub use yerpc;
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
//!
|
//!
|
||||||
//! For received messages, DelSp parameter is honoured.
|
//! For received messages, DelSp parameter is honoured.
|
||||||
#![cfg_attr(not(test), forbid(clippy::indexing_slicing))]
|
#![cfg_attr(not(test), forbid(clippy::indexing_slicing))]
|
||||||
|
#![cfg_attr(not(test), forbid(clippy::string_slice))]
|
||||||
|
|
||||||
/// Wraps line to 72 characters using format=flowed soft breaks.
|
/// Wraps line to 72 characters using format=flowed soft breaks.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
clippy::cloned_instead_of_copied
|
clippy::cloned_instead_of_copied
|
||||||
)]
|
)]
|
||||||
#![cfg_attr(not(test), forbid(clippy::indexing_slicing))]
|
#![cfg_attr(not(test), forbid(clippy::indexing_slicing))]
|
||||||
|
#![cfg_attr(not(test), forbid(clippy::string_slice))]
|
||||||
#![allow(
|
#![allow(
|
||||||
clippy::match_bool,
|
clippy::match_bool,
|
||||||
clippy::mixed_read_write_in_expression,
|
clippy::mixed_read_write_in_expression,
|
||||||
|
|||||||
15
src/qr.rs
15
src/qr.rs
@@ -807,11 +807,7 @@ async fn decode_mailto(context: &Context, qr: &str) -> Result<Qr> {
|
|||||||
.get(MAILTO_SCHEME.len()..)
|
.get(MAILTO_SCHEME.len()..)
|
||||||
.context("Invalid mailto: scheme")?;
|
.context("Invalid mailto: scheme")?;
|
||||||
|
|
||||||
let (addr, query) = if let Some(query_index) = payload.find('?') {
|
let (addr, query) = payload.split_once('?').unwrap_or((payload, ""));
|
||||||
(&payload[..query_index], &payload[query_index + 1..])
|
|
||||||
} else {
|
|
||||||
(payload, "")
|
|
||||||
};
|
|
||||||
|
|
||||||
let param: BTreeMap<&str, &str> = query
|
let param: BTreeMap<&str, &str> = query
|
||||||
.split('&')
|
.split('&')
|
||||||
@@ -861,12 +857,9 @@ async fn decode_mailto(context: &Context, qr: &str) -> Result<Qr> {
|
|||||||
async fn decode_smtp(context: &Context, qr: &str) -> Result<Qr> {
|
async fn decode_smtp(context: &Context, qr: &str) -> Result<Qr> {
|
||||||
let payload = qr.get(SMTP_SCHEME.len()..).context("Invalid SMTP scheme")?;
|
let payload = qr.get(SMTP_SCHEME.len()..).context("Invalid SMTP scheme")?;
|
||||||
|
|
||||||
let addr = if let Some(query_index) = payload.find(':') {
|
let (addr, _rest) = payload
|
||||||
&payload[..query_index]
|
.split_once(':')
|
||||||
} else {
|
.context("Invalid SMTP scheme payload")?;
|
||||||
bail!("Invalid SMTP found");
|
|
||||||
};
|
|
||||||
|
|
||||||
let addr = normalize_address(addr)?;
|
let addr = normalize_address(addr)?;
|
||||||
let name = "";
|
let name = "";
|
||||||
Qr::from_address(context, name, &addr, None).await
|
Qr::from_address(context, name, &addr, None).await
|
||||||
|
|||||||
@@ -347,7 +347,7 @@ pub(crate) async fn handle_securejoin_handshake(
|
|||||||
send_alice_handshake_msg(
|
send_alice_handshake_msg(
|
||||||
context,
|
context,
|
||||||
contact_id,
|
contact_id,
|
||||||
&format!("{}-auth-required", &step[..2]),
|
&format!("{}-auth-required", &step.get(..2).unwrap_or_default()),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.context("failed sending auth-required handshake message")?;
|
.context("failed sending auth-required handshake message")?;
|
||||||
|
|||||||
31
src/tools.rs
31
src/tools.rs
@@ -47,20 +47,27 @@ use crate::stock_str;
|
|||||||
/// end of the shortened string.
|
/// end of the shortened string.
|
||||||
pub(crate) fn truncate(buf: &str, approx_chars: usize) -> Cow<str> {
|
pub(crate) fn truncate(buf: &str, approx_chars: usize) -> Cow<str> {
|
||||||
let count = buf.chars().count();
|
let count = buf.chars().count();
|
||||||
if count > approx_chars + DC_ELLIPSIS.len() {
|
if count <= approx_chars + DC_ELLIPSIS.len() {
|
||||||
let end_pos = buf
|
return Cow::Borrowed(buf);
|
||||||
.char_indices()
|
}
|
||||||
.nth(approx_chars)
|
let end_pos = buf
|
||||||
.map(|(n, _)| n)
|
.char_indices()
|
||||||
.unwrap_or_default();
|
.nth(approx_chars)
|
||||||
|
.map(|(n, _)| n)
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
if let Some(index) = buf[..end_pos].rfind([' ', '\n']) {
|
if let Some(index) = buf.get(..end_pos).and_then(|s| s.rfind([' ', '\n'])) {
|
||||||
Cow::Owned(format!("{}{}", &buf[..=index], DC_ELLIPSIS))
|
Cow::Owned(format!(
|
||||||
} else {
|
"{}{}",
|
||||||
Cow::Owned(format!("{}{}", &buf[..end_pos], DC_ELLIPSIS))
|
&buf.get(..=index).unwrap_or_default(),
|
||||||
}
|
DC_ELLIPSIS
|
||||||
|
))
|
||||||
} else {
|
} else {
|
||||||
Cow::Borrowed(buf)
|
Cow::Owned(format!(
|
||||||
|
"{}{}",
|
||||||
|
&buf.get(..end_pos).unwrap_or_default(),
|
||||||
|
DC_ELLIPSIS
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user