Merge pull request #301 from ChloroplastYu/patch-1

Solution: add a new solution for ownership-4
This commit is contained in:
Sunface 2022-08-22 09:06:07 +08:00 committed by GitHub
commit 331ec6dbec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 1 deletions

View File

@ -96,6 +96,17 @@ fn print_str(s: String) {
}
```
```rust
fn main() {
let s = String::from("hello, world");
print_str(&s);
println!("{}", s);
}
fn print_str(s: &String) {
println!("{}",s)
}
```
5.
```rust
@ -157,4 +168,4 @@ fn main() {
println!("{:?}, {:?}, {:?}", s1, s2, t); // -> "hello", "world", ("hello", "world")
}
```
```