Last active
May 5, 2022 05:35
-
-
Save gembin/7b9b16d19568aedfebf8af35d7238b15 to your computer and use it in GitHub Desktop.
Revisions
-
gembin revised this gist
May 5, 2022 . 1 changed file with 37 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,4 +2,40 @@ ```rust let v: Vec<&str> = v.iter().map(AsRef::as_ref).collect(); ``` ### Convert a collection of characters into a String 1. chars.iter().collect::<String>() ```rust // Vec<char> -> String let chars = vec!['a', 'b', 'c']; let string = chars.iter().collect::<String>(); // [char] -> String let chars = ['a', 'b', 'c']; let string = chars.iter().collect::<String>(); // &[char] -> String let slice_chars = &chars[..]; let string = slice_chars.iter().collect::<String>(); ``` 2. chars.concat() ```rust // Vec<char> -> String let chars = vec!["a", "b", "c"]; let string = chars.concat(); ``` 3. strings.join(separator) ```rust let names = ["firstName", "lastName"]; let joined = names.join(", "); ```
-
gembin created this gist
May 5, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ ### Convert a Vec<String> to Vec<&str> ```rust let v: Vec<&str> = v.iter().map(AsRef::as_ref).collect(); ```