Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: simplify statements for readability #909

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ async fn oauth(url: &str) -> Credentials {
.danger_accept_invalid_certs(is_localhost(url))
.build()
.unwrap_or_default()
.get(format!("{}/.well-known/oauth-authorization-server", url))
.get(format!("{url}/.well-known/oauth-authorization-server"))
.send()
.await
.unwrap_result("send OAuth GET request")
Expand Down Expand Up @@ -285,22 +285,22 @@ impl Display for ManagementApiError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ManagementApiError::FieldAlreadyExists { field, value } => {
write!(f, "Field {} already exists with value {}.", field, value)
write!(f, "Field {field} already exists with value {value}.")
}
ManagementApiError::FieldMissing { field } => {
write!(f, "Field {} is missing.", field)
write!(f, "Field {field} is missing.")
}
ManagementApiError::NotFound { item } => {
write!(f, "{} not found.", item)
write!(f, "{item} not found.")
}
ManagementApiError::Unsupported { details } => {
write!(f, "Unsupported: {}", details)
write!(f, "Unsupported: {details}")
}
ManagementApiError::AssertFailed => {
write!(f, "Assertion failed.")
}
ManagementApiError::Other { details } => {
write!(f, "{}", details)
write!(f, "{details}")
}
}
}
Expand Down
32 changes: 6 additions & 26 deletions crates/cli/src/modules/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ impl ImportCommands {
failures
.lock()
.unwrap()
.push(format!("I/O error reading message: {}", e));
.push(format!("I/O error reading message: {e}"));
}
}
}
Expand All @@ -414,7 +414,7 @@ impl ImportCommands {
if !failures.is_empty() {
eprintln!("There were {} failures:\n", failures.len());
for failure in failures.iter() {
eprintln!("{}", failure);
eprintln!("{failure}");
}
}
}
Expand Down Expand Up @@ -645,22 +645,12 @@ async fn import_emails(
Ok(mut file) => match file.read_to_end(&mut contents).await {
Ok(_) => {}
Err(err) => {
eprintln!(
"Failed to read blob file for emailId {id} at {path:?}: {err}",
id = id,
path = path,
err = err
);
eprintln!("Failed to read blob file for emailId {id} at {path:?}: {err}");
return;
}
},
Err(err) => {
eprintln!(
"Failed to open blob file for emailId {id} at {path:?}: {err}",
id = id,
path = path,
err = err
);
eprintln!("Failed to open blob file for emailId {id} at {path:?}: {err}");
return;
}
}
Expand Down Expand Up @@ -771,22 +761,12 @@ async fn import_sieve_scripts(
Ok(mut file) => match file.read_to_end(&mut contents).await {
Ok(_) => {}
Err(err) => {
eprintln!(
"Failed to read blob file for script {id} at {path:?}: {err}",
id = id,
path = path,
err = err
);
eprintln!("Failed to read blob file for script {id} at {path:?}: {err}");
return;
}
},
Err(err) => {
eprintln!(
"Failed to open blob file for script {id} at {path:?}: {err}",
id = id,
path = path,
err = err
);
eprintln!("Failed to open blob file for script {id} at {path:?}: {err}");
return;
}
}
Expand Down
14 changes: 7 additions & 7 deletions crates/cli/src/modules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ impl<T> UnwrapResult<T> for Option<T> {
match self {
Some(result) => result,
None => {
eprintln!("Failed to {}", message);
eprintln!("Failed to {message}");
std::process::exit(1);
}
}
Expand All @@ -184,7 +184,7 @@ impl<T, E: Display> UnwrapResult<T> for Result<T, E> {
match self {
Ok(result) => result,
Err(err) => {
eprintln!("Failed to {}: {}", message, err);
eprintln!("Failed to {message}: {err}");
std::process::exit(1);
}
}
Expand All @@ -206,7 +206,7 @@ pub fn read_file(path: &str) -> Vec<u8> {
raw_message
} else {
std::fs::read(path).unwrap_or_else(|_| {
eprintln!("Failed to read file: {}", path);
eprintln!("Failed to read file: {path}");
std::process::exit(1);
})
}
Expand All @@ -225,11 +225,11 @@ pub async fn name_to_id(client: &Client, name: &str) -> String {
match response.ids().len() {
1 => response.take_ids().pop().unwrap(),
0 => {
eprintln!("Error: No principal found with name '{}'.", name);
eprintln!("Error: No principal found with name '{name}'.");
std::process::exit(1);
}
_ => {
eprintln!("Error: Multiple principals found with name '{}'.", name);
eprintln!("Error: Multiple principals found with name '{name}'.");
std::process::exit(1);
}
}
Expand All @@ -251,8 +251,8 @@ pub trait OAuthResponse {
impl OAuthResponse for HashMap<String, serde_json::Value> {
fn property(&self, name: &str) -> &str {
self.get(name)
.unwrap_result(&format!("find '{}' in OAuth response", name))
.unwrap_result(&format!("find '{name}' in OAuth response"))
.as_str()
.unwrap_result(&format!("invalid '{}' value", name))
.unwrap_result(&format!("invalid '{name}' value"))
}
}
4 changes: 2 additions & 2 deletions crates/common/src/addresses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl AddressMapping {
AddressMapping::Enable => {
if let Some((local_part, domain_part)) = address.rsplit_once('@') {
if let Some((local_part, _)) = local_part.split_once('+') {
return format!("{}@{}", local_part, domain_part).into();
return format!("{local_part}@{domain_part}").into();
}
}
}
Expand All @@ -211,7 +211,7 @@ impl AddressMapping {
match self {
AddressMapping::Enable => address
.rsplit_once('@')
.map(|(_, domain_part)| format!("@{}", domain_part))
.map(|(_, domain_part)| format!("@{domain_part}"))
.map(Cow::Owned),
AddressMapping::Custom(if_block) => core
.eval_if::<String, _>(if_block, &Address(address), session_id)
Expand Down
9 changes: 4 additions & 5 deletions crates/common/src/auth/access_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,9 @@ impl AccessToken {
if self.has_access(to_account_id.document_id(), to_collection) {
Ok(self)
} else {
Err(trc::JmapEvent::Forbidden.into_err().details(format!(
"You do not have access to account {}",
to_account_id
)))
Err(trc::JmapEvent::Forbidden
.into_err()
.details(format!("You do not have access to account {to_account_id}")))
}
}

Expand All @@ -335,7 +334,7 @@ impl AccessToken {
} else {
Err(trc::JmapEvent::Forbidden
.into_err()
.details(format!("You are not an owner of account {}", account_id)))
.details(format!("You are not an owner of account {account_id}")))
}
}

Expand Down
12 changes: 6 additions & 6 deletions crates/common/src/auth/oauth/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl OAuthConfig {
_ => {
config.new_parse_error(
"oauth.oidc.signature-algorithm",
format!("Invalid OIDC signature algorithm: {}", alg),
format!("Invalid OIDC signature algorithm: {alg}"),
);
SignatureAlgorithm::HS256
}
Expand Down Expand Up @@ -226,7 +226,7 @@ fn parse_rsa_key(config: &mut Config) -> Option<(Secret, AlgorithmParameters)> {
Err(err) => {
config.new_build_error(
"oauth.oidc.signature-key",
format!("Failed to build RSA key: {}", err),
format!("Failed to build RSA key: {err}"),
);
return None;
}
Expand All @@ -237,7 +237,7 @@ fn parse_rsa_key(config: &mut Config) -> Option<(Secret, AlgorithmParameters)> {
Err(err) => {
config.new_build_error(
"oauth.oidc.signature-key",
format!("Failed to obtain RSA public key: {}", err),
format!("Failed to obtain RSA public key: {err}"),
);
return None;
}
Expand Down Expand Up @@ -279,7 +279,7 @@ fn parse_ecdsa_key(
Err(err) => {
config.new_build_error(
"oauth.oidc.signature-key",
format!("Failed to build ECDSA key: {}", err),
format!("Failed to build ECDSA key: {err}"),
);
return None;
}
Expand All @@ -294,7 +294,7 @@ fn parse_ecdsa_key(
Err(err) => {
config.new_build_error(
"oauth.oidc.signature-key",
format!("Failed to parse ECDSA key: {}", err),
format!("Failed to parse ECDSA key: {err}"),
);
return None;
}
Expand All @@ -311,7 +311,7 @@ fn parse_ecdsa_key(
Err(err) => {
config.new_build_error(
"oauth.oidc.signature-key",
format!("Failed to parse ECDSA key: {}", err),
format!("Failed to parse ECDSA key: {err}"),
);
return None;
}
Expand Down
9 changes: 3 additions & 6 deletions crates/common/src/config/jmap/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,21 +111,18 @@ impl JmapConfig {
Ok((
hyper::header::HeaderName::from_str(k.trim()).map_err(|err| {
format!(
"Invalid header found in property \"server.http.headers\": {}",
err
"Invalid header found in property \"server.http.headers\": {err}"
)
})?,
hyper::header::HeaderValue::from_str(v.trim()).map_err(|err| {
format!(
"Invalid header found in property \"server.http.headers\": {}",
err
"Invalid header found in property \"server.http.headers\": {err}"
)
})?,
))
} else {
Err(format!(
"Invalid header found in property \"server.http.headers\": {}",
v
"Invalid header found in property \"server.http.headers\": {v}"
))
}
})
Expand Down
4 changes: 2 additions & 2 deletions crates/common/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,13 +273,13 @@ pub(crate) fn parse_http_headers(config: &mut Config, prefix: impl AsKey) -> Hea
AUTHORIZATION,
format!(
"Basic {}",
general_purpose::STANDARD.encode(format!("{}:{}", name, secret))
general_purpose::STANDARD.encode(format!("{name}:{secret}"))
)
.parse()
.unwrap(),
);
} else if let Some(token) = config.value((&prefix, "auth.token")) {
headers.insert(AUTHORIZATION, format!("Bearer {}", token).parse().unwrap());
headers.insert(AUTHORIZATION, format!("Bearer {token}").parse().unwrap());
}

headers
Expand Down
2 changes: 1 addition & 1 deletion crates/common/src/config/server/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ impl ParseValue for ServerProtocol {
} else if value.eq_ignore_ascii_case("pop3") {
Ok(Self::Pop3)
} else {
Err(format!("Invalid server protocol type {:?}.", value,))
Err(format!("Invalid server protocol type {value:?}.",))
}
}
}
2 changes: 1 addition & 1 deletion crates/common/src/config/smtp/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ impl ParseValue for VerifyStrategy {
"relaxed" => Ok(VerifyStrategy::Relaxed),
"strict" => Ok(VerifyStrategy::Strict),
"disable" | "disabled" | "never" | "none" => Ok(VerifyStrategy::Disable),
_ => Err(format!("Invalid value {:?}.", value)),
_ => Err(format!("Invalid value {value:?}.")),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/common/src/config/smtp/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ impl ParseValue for RequireOptional {
"optional" => Ok(RequireOptional::Optional),
"require" | "required" => Ok(RequireOptional::Require),
"disable" | "disabled" | "none" | "false" => Ok(RequireOptional::Disable),
_ => Err(format!("Invalid TLS option value {:?}.", value,)),
_ => Err(format!("Invalid TLS option value {value:?}.",)),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/common/src/config/smtp/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ impl ParseValue for AggregateFrequency {
"hourly" | "hour" => Ok(AggregateFrequency::Hourly),
"weekly" | "week" => Ok(AggregateFrequency::Weekly),
"never" | "disable" | "false" => Ok(AggregateFrequency::Never),
_ => Err(format!("Invalid aggregate frequency value {:?}.", value,)),
_ => Err(format!("Invalid aggregate frequency value {value:?}.",)),
}
}
}
Expand Down Expand Up @@ -279,6 +279,6 @@ impl ParseValue for AddressMatch {
} else if value.contains('@') {
return Ok(AddressMatch::Equals(value.trim().to_lowercase()));
}
Err(format!("Invalid address match value {:?}.", value,))
Err(format!("Invalid address match value {value:?}.",))
}
}
6 changes: 3 additions & 3 deletions crates/common/src/config/smtp/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ fn parse_milter(config: &mut Config, id: &str, token_map: &TokenMap) -> Option<M
IfBlock::new::<()>(format!("session.milter.{id}.enable"), [], "false")
}),
id: id.to_string().into(),
addrs: format!("{}:{}", hostname, port)
addrs: format!("{hostname}:{port}")
.to_socket_addrs()
.map_err(|err| {
config.new_build_error(
Expand Down Expand Up @@ -636,7 +636,7 @@ fn parse_hooks(config: &mut Config, id: &str, token_map: &TokenMap) -> Option<MT
) {
headers.insert(
AUTHORIZATION,
format!("Basic {}", STANDARD.encode(format!("{}:{}", name, secret)))
format!("Basic {}", STANDARD.encode(format!("{name}:{secret}")))
.parse()
.unwrap(),
);
Expand Down Expand Up @@ -937,7 +937,7 @@ impl ParseValue for Mechanism {
"CRAM-MD5" => AUTH_CRAM_MD5,
"DIGEST-MD5" => AUTH_DIGEST_MD5,
"ANONYMOUS" => AUTH_ANONYMOUS,*/
_ => return Err(format!("Unsupported mechanism {:?}.", value)),
_ => return Err(format!("Unsupported mechanism {value:?}.")),
}))
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/common/src/enterprise/llm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,21 @@ impl AiApiConfig {
}],
temperature: temperature.unwrap_or(self.default_temperature),
})
.map_err(|err| format!("Failed to serialize request: {}", err))?,
.map_err(|err| format!("Failed to serialize request: {err}"))?,
ApiType::TextCompletion => serde_json::to_string(&TextCompletionRequest {
model: self.model.to_string(),
prompt: prompt.into(),
temperature: temperature.unwrap_or(self.default_temperature),
})
.map_err(|err| format!("Failed to serialize request: {}", err))?,
.map_err(|err| format!("Failed to serialize request: {err}"))?,
};

// Send request
let response = reqwest::Client::builder()
.timeout(self.timeout)
.danger_accept_invalid_certs(self.tls_allow_invalid_certs)
.build()
.map_err(|err| format!("Failed to create HTTP client: {}", err))?
.map_err(|err| format!("Failed to create HTTP client: {err}"))?
.post(&self.url)
.headers(self.headers.clone())
.body(body)
Expand Down
Loading