Use proper error handling instead of lurking panics everywhere
This commit is contained in:
1 parent
999987d157
commit
214ffef6f3
11 files changed
+349
-392
No files matched your search
+12
-4
@@ -1,6 +1,14 @@
|
||||
use nix::errno::Errno;
|
||||
use nix::time::{clock_gettime, ClockId};
|
||||
use thiserror::Error;
|
||||
|
||||
pub(crate) struct Utils {}
|
||||
#[derive(Debug, Error)]
|
||||
pub enum UtilError {
|
||||
#[error("libc error")]
|
||||
Libc(#[from] Errno),
|
||||
}
|
||||
|
||||
pub struct Utils {}
|
||||
|
||||
impl Utils {
|
||||
pub(crate) fn a_else_b(a: f64, b: f64) -> f64 {
|
||||
@@ -9,9 +17,9 @@ impl Utils {
|
||||
pub(crate) fn ewma_factor(tick: f64, dur: f64) -> f64 {
|
||||
((0.5_f64).ln() / (dur / tick)).exp()
|
||||
}
|
||||
pub(crate) fn get_current_time() -> (f64, f64) {
|
||||
let time = clock_gettime(ClockId::CLOCK_MONOTONIC).unwrap();
|
||||
(time.tv_sec() as f64, time.tv_nsec() as f64)
|
||||
pub(crate) fn get_current_time() -> Result<(f64, f64), UtilError> {
|
||||
let time = clock_gettime(ClockId::CLOCK_MONOTONIC)?;
|
||||
Ok((time.tv_sec() as f64, time.tv_nsec() as f64))
|
||||
}
|
||||
|
||||
#[cfg(target_endian = "big")]
|
||||
|
||||
Reference in new issue
Block a user