Skip to content

Commit ec36f46

Browse files
committed
change String::from_str() to .to_string()
1 parent 6959931 commit ec36f46

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

src/doc/tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1621,7 +1621,7 @@ let more_numbers: Vec<int> = numbers.move_iter().map(|i| i+1).collect();
16211621
16221622
// The original `numbers` value can no longer be used, due to move semantics.
16231623
1624-
let mut string = String::from_str("fo");
1624+
let mut string = "fo".to_string();
16251625
string.push_char('o');
16261626
~~~
16271627

src/liballoc/rc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ struct Gadget {
4848
fn main() {
4949
// Create a reference counted Owner.
5050
let gadget_owner : Rc<Owner> = Rc::new(
51-
Owner { name: String::from_str("Gadget Man") }
51+
Owner { name: "Gadget Man".to_string() }
5252
);
5353
5454
// Create Gadgets belonging to gadget_owner. To increment the reference

src/libcollections/string.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ mod tests {
387387

388388
#[test]
389389
fn test_push_bytes() {
390-
let mut s = String::from_str("ABC");
390+
let mut s = "ABC".to_string();
391391
unsafe {
392392
s.push_bytes([ 'D' as u8 ]);
393393
}
@@ -407,7 +407,7 @@ mod tests {
407407

408408
#[test]
409409
fn test_push_char() {
410-
let mut data = String::from_str("ประเทศไทย中");
410+
let mut data = "ประเทศไทย中".to_string();
411411
data.push_char('华');
412412
data.push_char('b'); // 1 byte
413413
data.push_char('¢'); // 2 byte
@@ -418,7 +418,7 @@ mod tests {
418418

419419
#[test]
420420
fn test_pop_char() {
421-
let mut data = String::from_str("ประเทศไทย中华b¢€𤭢");
421+
let mut data = "ประเทศไทย中华b¢€𤭢".to_string();
422422
assert_eq!(data.pop_char().unwrap(), '𤭢'); // 4 bytes
423423
assert_eq!(data.pop_char().unwrap(), '€'); // 3 bytes
424424
assert_eq!(data.pop_char().unwrap(), '¢'); // 2 bytes
@@ -429,7 +429,7 @@ mod tests {
429429

430430
#[test]
431431
fn test_shift_char() {
432-
let mut data = String::from_str("𤭢€¢b华ประเทศไทย中");
432+
let mut data = "𤭢€¢b华ประเทศไทย中".to_string();
433433
assert_eq!(data.shift_char().unwrap(), '𤭢'); // 4 bytes
434434
assert_eq!(data.shift_char().unwrap(), '€'); // 3 bytes
435435
assert_eq!(data.shift_char().unwrap(), '¢'); // 2 bytes
@@ -440,15 +440,15 @@ mod tests {
440440

441441
#[test]
442442
fn test_str_truncate() {
443-
let mut s = String::from_str("12345");
443+
let mut s = "12345".to_string();
444444
s.truncate(5);
445445
assert_eq!(s.as_slice(), "12345");
446446
s.truncate(3);
447447
assert_eq!(s.as_slice(), "123");
448448
s.truncate(0);
449449
assert_eq!(s.as_slice(), "");
450450

451-
let mut s = String::from_str("12345");
451+
let mut s = "12345".to_string();
452452
let p = s.as_slice().as_ptr();
453453
s.truncate(3);
454454
s.push_str("6");
@@ -459,30 +459,30 @@ mod tests {
459459
#[test]
460460
#[should_fail]
461461
fn test_str_truncate_invalid_len() {
462-
let mut s = String::from_str("12345");
462+
let mut s = "12345".to_string();
463463
s.truncate(6);
464464
}
465465

466466
#[test]
467467
#[should_fail]
468468
fn test_str_truncate_split_codepoint() {
469-
let mut s = String::from_str("\u00FC"); // ü
469+
let mut s = "\u00FC".to_string(); // ü
470470
s.truncate(1);
471471
}
472472

473473
#[test]
474474
fn test_str_clear() {
475-
let mut s = String::from_str("12345");
475+
let mut s = "12345".to_string();
476476
s.clear();
477477
assert_eq!(s.len(), 0);
478478
assert_eq!(s.as_slice(), "");
479479
}
480480

481481
#[test]
482482
fn test_str_add() {
483-
let a = String::from_str("12345");
483+
let a = "12345".to_string();
484484
let b = a + "2";
485-
let b = b + String::from_str("2");
485+
let b = b + "2".to_string();
486486
assert_eq!(b.len(), 7);
487487
assert_eq!(b.as_slice(), "1234522");
488488
}

0 commit comments

Comments
 (0)