1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
macro_rules! mutated { () => { /// Returns the mutated value for further method /// calling. /// /// # Examples /// /// ``` /// use hypotaxis::ChainLink; /// /// #[derive(Debug, PartialEq)] /// struct Person(String); /// /// let names = ["Bob", "Alice", "Charlie"].to_vec(); /// /// let people_ordered = names /// .mutated( |names| { names /// .sort(); /// }) /// .into_iter() /// .map( /// |name| Person(name.to_string()) /// ) /// .collect::<Vec<_>>() /// ; /// /// assert_eq!(people_ordered, [ /// Person("Alice".to_string()), /// Person("Bob".to_string()), /// Person("Charlie".to_string()), /// ]) /// ``` fn mutated<F>( self, mutate: F ) -> Self where F: FnOnce(&mut Self) { let mut value = self; mutate(&mut value); value } }} pub(crate) use mutated;