Skip to content

Commit 426f700

Browse files
author
WaySLOG
committed
Merge pull request #119 from chareice/patch-1
bug fixed: Using String::from instead of String::new
2 parents 691eb75 + 66ec74e commit 426f700

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

12-ownership-system/12-01-ownership.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ b.rs:3 println!("{}", a);
6161
先看如下代码:
6262
```rust
6363
{
64-
let a: String = String::new("xyz");
64+
let a: String = String::from("xyz");
6565
let b = a;
6666
println!("{}", a);
6767
}
@@ -114,7 +114,7 @@ move前后的a和b对应内存的地址不同。
114114
如果我们想实现对**String**的”深拷贝“怎么办? 可以直接调用**String**的Clone特性实现对内存的值拷贝而不是简单的地址拷贝。
115115
```rust
116116
{
117-
let a: String = String::new("xyz");
117+
let a: String = String::from("xyz");
118118
let b = a.clone(); // <-注意此处的clone
119119
println!("{}", a);
120120
}

0 commit comments

Comments
 (0)