Skip to content

Commit f5ee868

Browse files
committed
To_String() cleanup for to_owned on method calls
1 parent 8b80eba commit f5ee868

File tree

3 files changed

+29
-29
lines changed

3 files changed

+29
-29
lines changed

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
//! )", &[]).unwrap();
2525
//! let me = Person {
2626
//! id: 0,
27-
//! name: "Steven".to_string(),
27+
//! name: "Steven".to_owned(),
2828
//! data: None
2929
//! };
3030
//! conn.execute("INSERT INTO person (name, data) VALUES ($1, $2)",
@@ -867,7 +867,7 @@ impl Connection {
867867
/// target: ConnectTarget::Unix(some_crazy_path),
868868
/// port: None,
869869
/// user: Some(UserInfo {
870-
/// user: "postgres".to_string(),
870+
/// user: "postgres".to_owned(),
871871
/// password: None
872872
/// }),
873873
/// database: None,

src/url.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ impl Url {
6565
// query and fragment
6666
let (query, fragment) = try!(get_query_fragment(rest));
6767

68-
let url = Url::new(scheme.to_string(),
68+
let url = Url::new(scheme.to_owned(),
6969
userinfo,
70-
host.to_string(),
70+
host.to_owned(),
7171
port,
7272
path,
7373
query,
@@ -180,22 +180,22 @@ pub fn get_scheme(rawurl: &str) -> DecodeResult<(&str, &str)> {
180180
'0' ... '9' | '+' | '-' | '.' => {
181181
if i != 0 { continue }
182182

183-
Err("url: Scheme must begin with a letter.".to_string())
183+
Err("url: Scheme must begin with a letter.".to_owned())
184184
}
185185
':' => {
186186
if i == 0 {
187-
Err("url: Scheme cannot be empty.".to_string())
187+
Err("url: Scheme cannot be empty.".to_owned())
188188
} else {
189189
Ok((&rawurl[0..i], &rawurl[i+1..rawurl.len()]))
190190
}
191191
}
192-
_ => Err("url: Invalid character in scheme.".to_string()),
192+
_ => Err("url: Invalid character in scheme.".to_owned()),
193193
};
194194

195195
return result;
196196
}
197197

198-
Err("url: Scheme must be terminated with a colon.".to_string())
198+
Err("url: Scheme must be terminated with a colon.".to_owned())
199199
}
200200

201201
// returns userinfo, host, port, and unparsed part, or an error
@@ -255,7 +255,7 @@ fn get_authority(rawurl: &str) ->
255255
':' | '@' | '?' | '#' | '/' => {
256256
// separators, don't change anything
257257
}
258-
_ => return Err("Illegal character in authority".to_string()),
258+
_ => return Err("Illegal character in authority".to_owned()),
259259
}
260260

261261
// now process states
@@ -271,7 +271,7 @@ fn get_authority(rawurl: &str) ->
271271
// multiple colons means ipv6 address.
272272
if input == Input::Unreserved {
273273
return Err(
274-
"Illegal characters in IPv6 address.".to_string());
274+
"Illegal characters in IPv6 address.".to_owned());
275275
}
276276
st = State::Ip6Host;
277277
}
@@ -288,7 +288,7 @@ fn get_authority(rawurl: &str) ->
288288
}
289289
State::Ip6Port => {
290290
if input == Input::Unreserved {
291-
return Err("Illegal characters in authority.".to_string());
291+
return Err("Illegal characters in authority.".to_owned());
292292
}
293293
st = State::Ip6Host;
294294
}
@@ -299,7 +299,7 @@ fn get_authority(rawurl: &str) ->
299299
st = State::InPort;
300300
}
301301
}
302-
_ => return Err("Invalid ':' in authority.".to_string()),
302+
_ => return Err("Invalid ':' in authority.".to_owned()),
303303
}
304304
input = Input::Digit; // reset input class
305305
}
@@ -319,7 +319,7 @@ fn get_authority(rawurl: &str) ->
319319
userinfo = Some(UserInfo::new(user, Some(pass)));
320320
st = State::InHost;
321321
}
322-
_ => return Err("Invalid '@' in authority.".to_string()),
322+
_ => return Err("Invalid '@' in authority.".to_owned()),
323323
}
324324
begin = i+1;
325325
}
@@ -338,7 +338,7 @@ fn get_authority(rawurl: &str) ->
338338
State::PassHostPort
339339
| State::Ip6Port => {
340340
if input != Input::Digit {
341-
return Err("Non-digit characters in port.".to_string());
341+
return Err("Non-digit characters in port.".to_owned());
342342
}
343343
host = &rawurl[begin..pos];
344344
port = Some(&rawurl[pos+1..end]);
@@ -347,7 +347,7 @@ fn get_authority(rawurl: &str) ->
347347
| State::InHost => host = &rawurl[begin..end],
348348
State::InPort => {
349349
if input != Input::Digit {
350-
return Err("Non-digit characters in port.".to_string());
350+
return Err("Non-digit characters in port.".to_owned());
351351
}
352352
port = Some(&rawurl[pos+1..end]);
353353
}
@@ -384,13 +384,13 @@ fn get_path(rawurl: &str, is_authority: bool) -> DecodeResult<(String, &str)> {
384384
end = i;
385385
break;
386386
}
387-
_ => return Err("Invalid character in path.".to_string())
387+
_ => return Err("Invalid character in path.".to_owned())
388388
}
389389
}
390390

391391
if is_authority && end != 0 && !rawurl.starts_with("/") {
392392
Err("Non-empty path must begin with \
393-
'/' in presence of authority.".to_string())
393+
'/' in presence of authority.".to_owned())
394394
} else {
395395
Ok((try!(decode_component(&rawurl[0..end])), &rawurl[end..len]))
396396
}

tests/types/mod.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ fn test_i8_params() {
5252

5353
#[test]
5454
fn test_name_params() {
55-
test_type("NAME", &[(Some("hello world".to_string()), "'hello world'"),
56-
(Some("イロハニホヘト チリヌルヲ".to_string()), "'イロハニホヘト チリヌルヲ'"),
55+
test_type("NAME", &[(Some("hello world".to_owned()), "'hello world'"),
56+
(Some("イロハニホヘト チリヌルヲ".to_owned()), "'イロハニホヘト チリヌルヲ'"),
5757
(None, "NULL")]);
5858
}
5959

@@ -99,15 +99,15 @@ fn test_f64_params() {
9999

100100
#[test]
101101
fn test_varchar_params() {
102-
test_type("VARCHAR", &[(Some("hello world".to_string()), "'hello world'"),
103-
(Some("イロハニホヘト チリヌルヲ".to_string()), "'イロハニホヘト チリヌルヲ'"),
102+
test_type("VARCHAR", &[(Some("hello world".to_owned()), "'hello world'"),
103+
(Some("イロハニホヘト チリヌルヲ".to_owned()), "'イロハニホヘト チリヌルヲ'"),
104104
(None, "NULL")]);
105105
}
106106

107107
#[test]
108108
fn test_text_params() {
109-
test_type("TEXT", &[(Some("hello world".to_string()), "'hello world'"),
110-
(Some("イロハニホヘト チリヌルヲ".to_string()), "'イロハニホヘト チリヌルヲ'"),
109+
test_type("TEXT", &[(Some("hello world".to_owned()), "'hello world'"),
110+
(Some("イロハニホヘト チリヌルヲ".to_owned()), "'イロハニホヘト チリヌルヲ'"),
111111
(None, "NULL")]);
112112
}
113113

@@ -123,7 +123,7 @@ fn test_bpchar_params() {
123123
let stmt = or_panic!(conn.prepare("SELECT b FROM foo ORDER BY id"));
124124
let res = or_panic!(stmt.query(&[]));
125125

126-
assert_eq!(vec!(Some("12345".to_string()), Some("123 ".to_string()), None),
126+
assert_eq!(vec!(Some("12345".to_owned()), Some("123 ".to_owned()), None),
127127
res.iter().map(|row| row.get(0)).collect::<Vec<_>>());
128128
}
129129

@@ -158,10 +158,10 @@ fn test_hstore_params() {
158158
})
159159
}
160160
test_type("hstore",
161-
&[(Some(make_map!("a".to_string() => Some("1".to_string()))), "'a=>1'"),
162-
(Some(make_map!("hello".to_string() => Some("world!".to_string()),
163-
"hola".to_string() => Some("mundo!".to_string()),
164-
"what".to_string() => None)),
161+
&[(Some(make_map!("a".to_owned() => Some("1".to_owned()))), "'a=>1'"),
162+
(Some(make_map!("hello".to_owned() => Some("world!".to_owned()),
163+
"hola".to_owned() => Some("mundo!".to_owned()),
164+
"what".to_owned() => None)),
165165
"'hello=>world!,hola=>mundo!,what=>NULL'"),
166166
(None, "NULL")]);
167167
}
@@ -203,7 +203,7 @@ fn test_slice() {
203203

204204
let stmt = conn.prepare("SELECT f FROM foo WHERE id = ANY($1)").unwrap();
205205
let result = stmt.query(&[&Slice(&[1i32, 3, 4])]).unwrap();
206-
assert_eq!(vec!["a".to_string(), "c".to_string(), "d".to_string()],
206+
assert_eq!(vec!["a".to_owned(), "c".to_owned(), "d".to_owned()],
207207
result.iter().map(|r| r.get::<_, String>(0)).collect::<Vec<_>>());
208208
}
209209

0 commit comments

Comments
 (0)