From 69643c9db009e2c277196c1644d408dc0ecadb05 Mon Sep 17 00:00:00 2001 From: Chloroplast <51773819+ChloroplastYu@users.noreply.github.com> Date: Sun, 21 Aug 2022 17:02:48 +0800 Subject: [PATCH] Solution: add a new solution for ownership-4 --- solutions/ownership/ownership.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/solutions/ownership/ownership.md b/solutions/ownership/ownership.md index 1cd5f74..da93530 100644 --- a/solutions/ownership/ownership.md +++ b/solutions/ownership/ownership.md @@ -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") } -``` \ No newline at end of file +```