Commit 39fafd6
committed
auto merge of #8204 : kballard/rust/str-into-owned, r=graydon
The method .into_owned() is meant to be used as an optimization when you
need to get a ~str from a Str, but don't want to unnecessarily copy it
if it's already a ~str.
This is meant to ease functions that look like
fn foo<S: Str>(strs: &[S])
Previously they could work with the strings as slices using .as_slice(),
but producing ~str required copying the string, even if the vector
turned out be a &[~str] already.
I don't have any concrete uses for this yet, since the one conversion I've done to `&[S]` so far (see PR #8203) didn't actually need owned strings. But having this here may make using `Str` more attractive.
It also may be worth adding an `into_managed()` function, but that one is less obviously useful than `into_owned()`.1 file changed
Lines changed: 12 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1079 | 1079 | | |
1080 | 1080 | | |
1081 | 1081 | | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
1082 | 1085 | | |
1083 | 1086 | | |
1084 | 1087 | | |
1085 | 1088 | | |
1086 | 1089 | | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
1087 | 1093 | | |
1088 | 1094 | | |
1089 | 1095 | | |
1090 | 1096 | | |
1091 | 1097 | | |
1092 | 1098 | | |
1093 | 1099 | | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
1094 | 1103 | | |
1095 | 1104 | | |
1096 | 1105 | | |
1097 | 1106 | | |
1098 | 1107 | | |
1099 | 1108 | | |
1100 | 1109 | | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
1101 | 1113 | | |
1102 | 1114 | | |
1103 | 1115 | | |
| |||
0 commit comments