daily pastebin goal
42%
SHARE
TWEET

Untitled

a guest Jan 22nd, 2019 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. macro_rules! update {
  2.         (&$data:ident, $( $key:ident = $x:expr ),*) => (
  3.             {
  4.                 fn clone<T>(data: &T) -> T
  5.                     where T: Clone {
  6.                         data.clone()
  7.                     }
  8.                 let cp =  clone(&$data);
  9.                 update!(cp,  $( $key = $x ),*)
  10.             }
  11.         );
  12.         ($data:ident, $( $key:ident = $x:expr ),*) => (
  13.             {
  14.                 let mut data_m =  $data;
  15.                 $(
  16.                     data_m.$key=$x;
  17.                 )*
  18.                 data_m
  19.             }
  20.         );
  21.         ($data_e:expr, $( $key:ident = $x:expr ),*) => (
  22.             {
  23.                 let data = $data_e;
  24.                 update!(data, $( $key = $x ),*)
  25.             }
  26.         );
  27. }
  28.  
  29.  
  30. #[derive(Debug, Clone, Default)]
  31. struct Point {
  32.     x: i64,
  33.     y: i64,
  34.     s: String,
  35. }
  36.  
  37. fn main() {
  38.     let u = update!(Point::default(), x = 10);
  39.     println!("{:?}", u);
  40. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top