daily pastebin goal
30%
SHARE
TWEET

Untitled

a guest Jul 18th, 2018 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fn main() {
  2.     let mut a = vec!["a".to_string(), "b".to_string(), "c".to_string()];
  3.  
  4.     {
  5.         let c: Vec<&mut String> = a
  6.             .iter_mut()
  7.             .map(|x: &mut String| {
  8.                 x.push_str("第一次");
  9.                 x
  10.             })
  11.             .collect();
  12.         println!("{:?}", c);
  13.     }
  14.  
  15.     {
  16.     let b: Vec<String> = a
  17.         .iter()
  18.         .map(|x: &String| {
  19.             let mut s: String = x.clone();
  20.             s.push_str("_第二次");
  21.             s
  22.         })
  23.         .collect();
  24.         println!("{:?}", b);
  25.     }
  26.     {
  27.     let b: Vec<String> = a
  28.         .into_iter()
  29.         .map(|x: String| {
  30.             x + "_第三次"
  31.         })
  32.         .collect();
  33.         println!("{:?}", b);
  34.     }
  35. }
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