lasprs 0.14.2

Library for Acoustic Signal Processing (Rust edition, with optional Python bindings via pyo3)
use std::fs;
use std::time::SystemTime;
use std::{collections::VecDeque, path::Path, sync::Arc};

use crate::Flt;
pub(crate) mod h5;

/// Find an unused buffer in a double-ended queue of Arc's of some type. Returns
/// one if it finds one, returns None if no one is found
///
/// # Args
///
/// - `q`: The double-ended queue to remove one from.
pub fn find_unused_buf<T>(q: &mut VecDeque<Arc<T>>) -> Option<Arc<T>>
where
{
    q.iter_mut()
        .position(|g| Arc::get_mut(g).is_some())
        .and_then(|p| q.remove(p))
}

/// Get the current timestamp (UTC) in seconds as a floating point number, as
/// offset from UNIX_EPOCH. Only uses number of seconds and milliseconds since
/// UNIX_EPOCH.
pub fn get_current_timestamp() -> Flt {
    let now = SystemTime::now();
    let duration = now
        .duration_since(SystemTime::UNIX_EPOCH)
        .expect("System clock thinks it is before UNIX_EPOCH");
    duration.as_secs_f64() as Flt
}

/// Get a timestamp based on last file modification time.
pub fn get_modified_timestamp(path: &Path) -> Result<Flt, std::io::Error> {
    let metadata = fs::metadata(path)?;
    let modified = metadata.modified()?;
    let duration = modified
        .duration_since(SystemTime::UNIX_EPOCH)
        .expect("System clock thinks it is before UNIX_EPOCH");
    Ok(duration.as_secs_f64() as Flt)
}