xuko-misc 0.6.1

Miscellaneous utilities for xuko
Documentation
//! xuko-misc provide miscellaneous utilities

/// Colors
pub mod color;

/// Profiling
pub mod profiling;

/// Path module
///
/// Provides utilities for [`Path`]s
pub mod path {

    use std::path::{Path, PathBuf};

    /// Search for file or directory `stub` in `search_locations`
    pub fn search_for_path(search_locations: &[&Path], stub: &str) -> Option<PathBuf> {
        for location in search_locations {
            let p = Path::new(location).join(stub);

            match p.try_exists() {
                Ok(true) => return Some(p),
                _ => continue,
            }
        }

        None
    }
}

/// C for-loop
///
/// # Examples
///
/// ```
/// use xuko_misc::cfor;
/// cfor!(for (let mut x = 0; x != 5; x += 1) {
///     println!("Hello! #{}", x + 1);
/// });
/// ```
#[macro_export]
macro_rules! cfor {
    (for ($init:stmt;$cond:expr;$inc:stmt) $body:tt) => {
        $init
        while $cond {
            $body
            $inc
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn cforloop() {
        cfor!(for (let mut x = 0; x != 5; x += 1) {
            println!("X is: {}", x + 1);
        });
    }
}