kx-utils 0.1.3

Common utils incubator
Documentation
//
#![allow(unused)]

/// Converts the parameter into a [String] using the [Into] trait.
///
/// Requires parameter to implement a [From] or [Into] trait to allow it be transformed.
pub fn s(v: impl Into<String>) -> String {
    v.into()
}

/// Converts the parameter into a [String] by calling `.to_string()`.
///
/// Unlike the [s] function, the value only need to have a [to_string] method. Preusmably it will
/// return a [String], but this macro doesn't make that gaurantee.
#[macro_export]
macro_rules! s {
    ($value:expr) => {
        $value.to_string()
    };
}

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

    #[test]
    fn s_converts_to_string() {
        let v = 123.to_string();
        let result = s("123");
        assert_eq!(result, v);
    }
}