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 string formatting for readability #7736

Open
wants to merge 2 commits into
base: master
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
6 changes: 2 additions & 4 deletions tuta-sdk/rust/sdk/src/crypto_entity_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ impl CryptoEntityClient {
.parse_entity::<T>(decrypted_entity)
.map_err(|e| ApiCallError::InternalSdkError {
error_message: format!(
"Failed to parse encrypted entity into proper types: {}",
e
"Failed to parse encrypted entity into proper types: {e}"
),
})?;
Ok(typed_entity)
Expand All @@ -83,8 +82,7 @@ impl CryptoEntityClient {
.parse_entity::<T>(parsed_entity)
.map_err(|error| ApiCallError::InternalSdkError {
error_message: format!(
"Failed to parse unencrypted entity into proper types: {}",
error
"Failed to parse unencrypted entity into proper types: {error}"
),
})?;
Ok(typed_entity)
Expand Down
11 changes: 5 additions & 6 deletions tuta-sdk/rust/sdk/src/entities/entity_facade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl EntityFacadeImpl {
Ok(instance_value.clone())
} else {
let bytes = Self::map_value_to_binary(value_type, instance_value)
.unwrap_or_else(|| panic!("invalid encrypted value {:?}", instance_value));
.unwrap_or_else(|| panic!("invalid encrypted value {instance_value:?}"));
let encrypted_data = session_key
.encrypt_data(bytes.as_slice(), iv)
.expect("Cannot encrypt data");
Expand Down Expand Up @@ -164,7 +164,7 @@ impl EntityFacadeImpl {
.assert_bytes()
.as_slice(),
)
.map_err(|err| ApiCallError::internal(format!("iv of illegal size {:?}", err)))?;
.map_err(|err| ApiCallError::internal(format!("iv of illegal size {err:?}")))?;

encrypted_value = Self::encrypt_value(model_value, instance_value, sk, final_iv)?
} else {
Expand Down Expand Up @@ -358,7 +358,7 @@ impl EntityFacadeImpl {
// Errors should be grouped inside the top-most object, so they should be
// extracted and removed from aggregates
if decrypted_aggregate.contains_key("_errors") {
let error_key = &format!("{}_{}", association_name, index);
let error_key = &format!("{association_name}_{index}");
self.extract_errors(
error_key,
&mut errors,
Expand All @@ -371,8 +371,7 @@ impl EntityFacadeImpl {
_ => {
return Err(ApiCallError::InternalSdkError {
error_message: format!(
"Invalid aggregate format. {} isn't a dict",
association_name
"Invalid aggregate format. {association_name} isn't a dict"
),
})
},
Expand Down Expand Up @@ -1132,7 +1131,7 @@ mod tests {
ElementValue::Dict(aggregate) => {
out.push_str(&format!("{}: {}\n", key, map_to_string(aggregate)))
},
_ => out.push_str(&format!("{}: {:?}\n", key, value)),
_ => out.push_str(&format!("{key}: {value:?}\n")),
}
}
out
Expand Down
2 changes: 1 addition & 1 deletion tuta-sdk/rust/sdk/src/instance_mapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ impl Serializer for ElementValueSerializer {
}

fn unsupported(data_type: &str) -> ! {
panic!("Unsupported data type: {}", data_type)
panic!("Unsupported data type: {data_type}")
}

impl SerializeSeq for ElementValueSeqSerializer {
Expand Down
2 changes: 1 addition & 1 deletion tuta-sdk/rust/sdk/src/key_loader_facade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl KeyLoaderFacade {

fn decode_group_key_version(&self, element_id: &GeneratedId) -> Result<i64, KeyLoadError> {
element_id.as_str().parse().map_err(|_| KeyLoadError {
reason: format!("Failed to decode group key version: {}", element_id),
reason: format!("Failed to decode group key version: {element_id}"),
})
}

Expand Down
2 changes: 1 addition & 1 deletion tuta-sdk/rust/sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ impl ApiCallError {
}
pub fn internal_with_err<E: Error>(error: E, message: &str) -> ApiCallError {
ApiCallError::InternalSdkError {
error_message: format!("{}: {}", error, message),
error_message: format!("{error}: {message}"),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions tuta-sdk/rust/sdk/src/login/login_facade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl TryFrom<i64> for KdfType {
0 => Ok(KdfType::Bcrypt),
1 => Ok(KdfType::Argon2id),
_ => Err(InternalSdkError {
error_message: format!("Failed to convert int {} into KdfType", value),
error_message: format!("Failed to convert int {value} into KdfType"),
}),
}
}
Expand Down Expand Up @@ -86,7 +86,7 @@ impl LoginFacade {
) -> Result<UserFacade, LoginError> {
let session_id = parse_session_id(credentials.access_token.as_str()).map_err(|e| {
LoginError::InvalidSessionId {
error_message: format!("Could not decode session id: {}", e),
error_message: format!("Could not decode session id: {e}"),
}
})?;
// Cannot use typed client because session is encrypted, and we haven't init crypto client yet
Expand Down
5 changes: 1 addition & 4 deletions tuta-sdk/rust/sdk/src/net/vec_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,5 @@ impl Buf for VecBuf {
/// Panic with a nice error message.
#[cold]
fn panic_advance(idx: usize, len: usize) -> ! {
panic!(
"advance out of bounds: the len is {} but advancing by {}",
len, idx
);
panic!("advance out of bounds: the len is {len} but advancing by {idx}");
}
3 changes: 1 addition & 2 deletions tuta-sdk/rust/sdk/src/services/service_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@ impl Executor for ServiceExecutor {
.type_model_provider
.get_type_model(input_type_ref.app, input_type_ref.type_)
.ok_or(ApiCallError::internal(format!(
"type {:?} does not exist",
input_type_ref
"type {input_type_ref:?} does not exist"
)))?;

let encrypted_parsed_entity = if type_model.is_encrypted() {
Expand Down
2 changes: 1 addition & 1 deletion tuta-sdk/rust/sdk/src/user_facade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl UserFacade {
.find(|g| g.group == *group_id)
.map(|m| m.to_owned())
.ok_or_else(|| ApiCallError::InternalSdkError {
error_message: format!("No group with groupId {} found!", group_id),
error_message: format!("No group with groupId {group_id} found!"),
})
}
}