Skip to content

Commit

Permalink
mut_ref
Browse files Browse the repository at this point in the history
  • Loading branch information
Dragon-taro committed Aug 22, 2019
1 parent 6840a2a commit 8e355a7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion exercises/mutable_reference/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions exercises/mutable_reference/src/main.rs
Expand Up @@ -7,21 +7,21 @@
*/

fn main() {
let (word_a, word_b) = words();
let (mut word_a, word_b) = words();
println!("単語1:{:?}\n単語2:{:?}", word_a, word_b);
let text = concat(word_a, word_b);
let text = concat(&mut word_a, &word_b);
println!("結合された結果:{:?}", text);
}

fn words() -> (String, String) {
(format!("こんにちは"), format!("世界"))
}

fn concat(mut prefix: String, postfix: String) -> String {
fn concat(prefix: &mut String, postfix: &String) -> String {
prefix.push(' ');
for c in postfix.chars() {
prefix.push(c);
}
prefix
}
prefix.to_string()
}

0 comments on commit 8e355a7

Please sign in to comment.