mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-04-28 01:49:05 +02:00
parent
2e6219c005
commit
bded36a214
63
po/ko.po
63
po/ko.po
@ -5560,6 +5560,27 @@ msgid ""
|
|||||||
"}\n"
|
"}\n"
|
||||||
"```"
|
"```"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
"```rust,editable\n"
|
||||||
|
"#[derive(Debug)]\n"
|
||||||
|
"struct Person {\n"
|
||||||
|
" name: String,\n"
|
||||||
|
" age: u8,\n"
|
||||||
|
"}\n"
|
||||||
|
"\n"
|
||||||
|
"impl Person {\n"
|
||||||
|
" fn say_hello(&self) {\n"
|
||||||
|
" println!(\"Hello, my name is {}\", self.name);\n"
|
||||||
|
" }\n"
|
||||||
|
"}\n"
|
||||||
|
"\n"
|
||||||
|
"fn main() {\n"
|
||||||
|
" let peter = Person {\n"
|
||||||
|
" name: String::from(\"Peter\"),\n"
|
||||||
|
" age: 27,\n"
|
||||||
|
" };\n"
|
||||||
|
" peter.say_hello();\n"
|
||||||
|
"}\n"
|
||||||
|
"```"
|
||||||
|
|
||||||
#: src/methods.md:31
|
#: src/methods.md:31
|
||||||
msgid ""
|
msgid ""
|
||||||
@ -5677,6 +5698,48 @@ msgid ""
|
|||||||
"}\n"
|
"}\n"
|
||||||
"```"
|
"```"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
"```rust,editable\n"
|
||||||
|
"#[derive(Debug)]\n"
|
||||||
|
"struct Race {\n"
|
||||||
|
" name: String,\n"
|
||||||
|
" laps: Vec<i32>,\n"
|
||||||
|
"}\n"
|
||||||
|
"\n"
|
||||||
|
"impl Race {\n"
|
||||||
|
" fn new(name: &str) -> Race { // No receiver, a static method\n"
|
||||||
|
" Race { name: String::from(name), laps: Vec::new() }\n"
|
||||||
|
" }\n"
|
||||||
|
"\n"
|
||||||
|
" fn add_lap(&mut self, lap: i32) { // Exclusive borrowed read-write "
|
||||||
|
"access to self\n"
|
||||||
|
" self.laps.push(lap);\n"
|
||||||
|
" }\n"
|
||||||
|
"\n"
|
||||||
|
" fn print_laps(&self) { // Shared and read-only borrowed access to self\n"
|
||||||
|
" println!(\"Recorded {} laps for {}:\", self.laps.len(), self.name);\n"
|
||||||
|
" for (idx, lap) in self.laps.iter().enumerate() {\n"
|
||||||
|
" println!(\"Lap {idx}: {lap} sec\");\n"
|
||||||
|
" }\n"
|
||||||
|
" }\n"
|
||||||
|
"\n"
|
||||||
|
" fn finish(self) { // Exclusive ownership of self\n"
|
||||||
|
" let total = self.laps.iter().sum::<i32>();\n"
|
||||||
|
" println!(\"Race {} is finished, total lap time: {}\", self.name, "
|
||||||
|
"total);\n"
|
||||||
|
" }\n"
|
||||||
|
"}\n"
|
||||||
|
"\n"
|
||||||
|
"fn main() {\n"
|
||||||
|
" let mut race = Race::new(\"Monaco Grand Prix\");\n"
|
||||||
|
" race.add_lap(70);\n"
|
||||||
|
" race.add_lap(68);\n"
|
||||||
|
" race.print_laps();\n"
|
||||||
|
" race.add_lap(71);\n"
|
||||||
|
" race.print_laps();\n"
|
||||||
|
" race.finish();\n"
|
||||||
|
" // race.add_lap(42);\n"
|
||||||
|
"}\n"
|
||||||
|
"```"
|
||||||
|
|
||||||
#: src/methods/example.md:47
|
#: src/methods/example.md:47
|
||||||
msgid ""
|
msgid ""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user