dbulfin-lib 0.1.0

Simple library to test docs and cargo publish
Documentation
pub trait ApplyAssign<T> {
    /// Applies a function to a variable and sets the variable to
    /// the resulting value
    ///
    /// # Examples
    /// ```
    /// use crate::dbulfin_lib::ApplyAssign;
    ///
    /// let mut x = (1, 2);
    /// x.app_ass(|(x, y)| (y, x));
    /// assert_eq!(x, (2, 1))
    /// ```
    fn app_ass<F>(&mut self, f: F)
    where
        F: FnOnce(T) -> T;
}

impl<T> ApplyAssign<T> for T
where
    T: Clone,
{
    fn app_ass<F>(&mut self, f: F)
    where
        F: FnOnce(T) -> T,
    {
        *self = f(self.clone())
    }
}

/// Reverse a String value char-wise
/// 
/// # Examples
/// ```
/// use crate::dbulfin_lib::rev_string;
///
/// let mut s = String::from("ABC");
/// assert_eq!(rev_string(s), String::from("CBA"))
/// ```
pub fn rev_string(s: String) ->String {
    s.chars().rev().collect()
}

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

    fn tuple_edit(x: (i32, i32)) -> (i32, i32) {
        (x.1, x.0)
    }

    fn vec_edit(x: Vec<i32>) -> Vec<i32> {
        x.into_iter().rev().collect()
    }

    #[test]
    fn tuples() {
        let mut x = (1, 2);

        x.app_ass(tuple_edit);

        assert_eq!(x, (2, 1))
    }

    #[test]
    fn vecs() {
        let mut x = vec![1, 2, 3];

        x.app_ass(vec_edit);

        assert_eq!(x, vec![3, 2, 1])
    }
}