clippy: Deny and fix `fallible_impl_from`
Instead of changing `impl From<SystemTime> for LocalTime` to `TryFrom`, the implementation was removed, as there are not many callsites, and they are well served by `LocalTime::now`. radicle-localtime: drop TryFrom SystemTime radicle-node: switch SystemTime usage with LocalTime
This commit is contained in:
parent
02318f199c
commit
001aba0d29
|
|
@ -81,6 +81,7 @@ radicle-surf = "0.26.0"
|
|||
[workspace.lints]
|
||||
clippy.type_complexity = "allow"
|
||||
clippy.enum_variant_names = "allow"
|
||||
clippy.fallible_impl_from = "deny"
|
||||
|
||||
[profile.container]
|
||||
inherits = "release"
|
||||
|
|
|
|||
|
|
@ -415,7 +415,7 @@ impl From<CommentArgs> for CommentAction {
|
|||
(None, Some(react), None) => CommentAction::React {
|
||||
revision,
|
||||
comment: react,
|
||||
emoji: emoji.unwrap(),
|
||||
emoji: emoji.expect("emoji must be Some when react is Some"),
|
||||
undo,
|
||||
},
|
||||
(None, None, Some(redact)) => CommentAction::Redact {
|
||||
|
|
|
|||
|
|
@ -30,15 +30,22 @@ impl LocalTime {
|
|||
pub fn now() -> Self {
|
||||
static LAST: atomic::AtomicU64 = atomic::AtomicU64::new(0);
|
||||
|
||||
let now = Self::from(SystemTime::now()).as_secs();
|
||||
let last = LAST.load(atomic::Ordering::SeqCst);
|
||||
let now = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.map(|duration| Self {
|
||||
millis: duration.as_millis(),
|
||||
})
|
||||
.expect("should run after 1970-01-01");
|
||||
|
||||
let last_in_secs = LAST.load(atomic::Ordering::SeqCst);
|
||||
let now_in_secs = now.as_secs();
|
||||
|
||||
// If the current time is in the past, return the last recorded time instead.
|
||||
if now < last {
|
||||
Self::from_secs(last)
|
||||
if now_in_secs < last_in_secs {
|
||||
Self::from_secs(last_in_secs)
|
||||
} else {
|
||||
LAST.store(now, atomic::Ordering::SeqCst);
|
||||
LocalTime::from_secs(now)
|
||||
LAST.store(now_in_secs, atomic::Ordering::SeqCst);
|
||||
now
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -94,15 +101,6 @@ impl LocalTime {
|
|||
}
|
||||
}
|
||||
|
||||
/// Convert a `SystemTime` into a local time.
|
||||
impl From<SystemTime> for LocalTime {
|
||||
fn from(system: SystemTime) -> Self {
|
||||
let millis = system.duration_since(UNIX_EPOCH).unwrap().as_millis();
|
||||
|
||||
Self { millis }
|
||||
}
|
||||
}
|
||||
|
||||
/// Subtract two local times. Yields a duration.
|
||||
impl std::ops::Sub<LocalTime> for LocalTime {
|
||||
type Output = LocalDuration;
|
||||
|
|
|
|||
|
|
@ -51,6 +51,9 @@ enum Logger {
|
|||
Systemd,
|
||||
}
|
||||
|
||||
// Required for Mac and potentially Windows as clippy complains because of the OS specific
|
||||
// guard below.
|
||||
#[allow(clippy::derivable_impls)]
|
||||
impl Default for Logger {
|
||||
fn default() -> Self {
|
||||
#[cfg(all(feature = "systemd", target_os = "linux"))]
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use std::collections::hash_map::Entry;
|
|||
use std::collections::VecDeque;
|
||||
use std::fmt::Debug;
|
||||
use std::sync::Arc;
|
||||
use std::time::{Instant, SystemTime};
|
||||
use std::time::Instant;
|
||||
use std::{io, net, time};
|
||||
|
||||
use crossbeam_channel as chan;
|
||||
|
|
@ -13,6 +13,7 @@ use cyphernet::addr::{HostName, InetHost, NetAddr};
|
|||
use cyphernet::encrypt::noise::{HandshakePattern, Keyset, NoiseState};
|
||||
use cyphernet::proxy::socks5;
|
||||
use cyphernet::{Digest, EcSk, Ecdh, Sha256};
|
||||
use localtime::LocalTime;
|
||||
use mio::net::TcpStream;
|
||||
use radicle::node::device::Device;
|
||||
|
||||
|
|
@ -510,7 +511,7 @@ where
|
|||
.sum();
|
||||
self.metrics.worker_queue_size = self.worker.len();
|
||||
|
||||
self.service.tick(SystemTime::now().into(), &self.metrics);
|
||||
self.service.tick(LocalTime::now(), &self.metrics);
|
||||
}
|
||||
|
||||
fn timer_reacted(&mut self) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue