Skip to content

Commit

Permalink
Use write! macro instead of separate function calls (#374)
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra authored Oct 15, 2023
1 parent a4412de commit 44753d9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
5 changes: 2 additions & 3 deletions crates/kitsune-core/src/mapping/mastodon/sealed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use scoped_futures::ScopedFutureExt;
use serde::{de::DeserializeOwned, Serialize};
use smol_str::SmolStr;
use speedy_uuid::Uuid;
use std::str::FromStr;
use std::{fmt::Write, str::FromStr};

#[derive(Clone, Copy)]
pub struct MapperState<'a> {
Expand Down Expand Up @@ -103,8 +103,7 @@ impl IntoMastodon for DbAccount {

let mut acct = self.username.clone();
if !self.local {
acct.push('@');
acct.push_str(&self.domain);
let _ = write!(acct, "@{}", self.domain);
}

let avatar = if let Some(avatar_id) = self.avatar_id {
Expand Down
19 changes: 12 additions & 7 deletions crates/kitsune-http-signatures/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use derive_builder::Builder;
use http::{header::DATE, request::Parts};
use std::{
cmp::min,
fmt::Write,
time::{Duration, SystemTime, SystemTimeError},
};
use time::{format_description::well_known::Rfc2822, OffsetDateTime};
Expand Down Expand Up @@ -130,19 +131,23 @@ impl TryFrom<SignatureHeader<'_>> for String {
);

if let Some(algorithm) = value.algorithm {
signature_header.push_str(",algorithm=\"");
signature_header.push_str(algorithm);
signature_header.push('"');
let _ = write!(signature_header, ",algorithm=\"{algorithm}\"");
}

if let Some(created) = value.created {
signature_header.push_str(",created=");
signature_header.push_str(&created.to_unix_timestamp()?.to_string());
let _ = write!(
signature_header,
",created={}",
created.to_unix_timestamp()?
);
}

if let Some(expires) = value.expires {
signature_header.push_str(",expires=");
signature_header.push_str(&expires.to_unix_timestamp()?.to_string());
let _ = write!(
signature_header,
",expires={}",
expires.to_unix_timestamp()?
);
}

Ok(signature_header)
Expand Down

0 comments on commit 44753d9

Please sign in to comment.