Skip to content

Commit

Permalink
fix(dumper): clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
nerodono authored and loyd committed Dec 21, 2024
1 parent 506889b commit 38aaf64
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion elfo-dumper/src/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl Dumper {
self.render_path(&mut path_swap);
let file = self
.file_registry
.acquire_for_write(&path, &mut path_swap)
.acquire_for_write(&path, &path_swap)
.await?;
if path != path_swap {
path.clear();
Expand Down
14 changes: 10 additions & 4 deletions elfo-dumper/src/config/dump_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl<'de> Deserialize<'de> for DumpPath {
D: serde::Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
Self::parse(s).map_err(|e| serde::de::Error::custom(e))
Self::parse(s).map_err(serde::de::Error::custom)
}
}

Expand All @@ -48,7 +48,7 @@ impl DumpPath {
Variable::Class => dest.push_str(vars.class),
Variable::Time { format } => {
let ts = vars.ts;
strftime(ts as i64, format, dest);
strftime(ts, format, dest);
}
}
}
Expand All @@ -60,7 +60,7 @@ impl DumpPath {
let size = *size as usize;
match data {
ComponentData::Variable(var) => {
Self::expand_variable(&var, &variables, to);
Self::expand_variable(var, &variables, to);
}
ComponentData::Path => {
to.push_str(&self.template[offset..offset + size]);
Expand Down Expand Up @@ -210,7 +210,10 @@ struct Component {

/// Convert unix timestamp to [`libc::tm`].
fn ts2tm(ts: i64) -> libc::tm {
// SAFETY: [`libc::tm`] is `#[repr(C)]` and contains
// only integral types.
let mut tm: libc::tm = unsafe { std::mem::zeroed() };
// SAFETY: safe, lol.
unsafe { libc::localtime_r(std::ptr::addr_of!(ts), std::ptr::addr_of_mut!(tm)) };

tm
Expand All @@ -219,9 +222,12 @@ fn ts2tm(ts: i64) -> libc::tm {
fn strftime(ts: i64, format: &cstr::Utf8CString, dest: &mut String) -> bool {
let tm = ts2tm(ts);
let mut formatted: [libc::c_char; FMT_TS_ARRAY_LEN] = [0; FMT_TS_ARRAY_LEN];
// SAFETY: calling function from libc is unsafe, but
// 1. formatted is valid buffer
// 2. tm is valid too.
let len = unsafe {
libc::strftime(
std::ptr::addr_of_mut!(formatted).cast(),
std::ptr::addr_of_mut!(formatted).cast::<libc::c_char>(),
FMT_TS_ARRAY_LEN,
format.as_ptr(),
std::ptr::addr_of!(tm),
Expand Down
4 changes: 2 additions & 2 deletions elfo-dumper/src/file_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl FileRegistry {
pub(crate) async fn open(&self, path: &str, force: bool) -> Result<()> {
let mut file = {
let mut files = self.files.lock();
Self::insert_handle(path, &mut *files)
Self::insert_handle(path, &mut files)
};

Self::open_inner(path, force, &mut file).await?;
Expand All @@ -57,7 +57,7 @@ impl FileRegistry {
files.remove(old_path);
}

Self::insert_handle(path, &mut *files)
Self::insert_handle(path, &mut files)
};

// NOTE: a bit racy part here, two threads observe
Expand Down

0 comments on commit 38aaf64

Please sign in to comment.