mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-03-18 05:37:52 +02:00
parent
4d11d59247
commit
15f5ced5f9
39
po/ko.po
39
po/ko.po
@ -10880,6 +10880,19 @@ msgid ""
|
||||
"}\n"
|
||||
"```"
|
||||
msgstr ""
|
||||
"```rust,editable\n"
|
||||
"static mut COUNTER: u32 = 0;\n"
|
||||
"\n"
|
||||
"fn add_to_counter(inc: u32) {\n"
|
||||
" unsafe { COUNTER += inc; } // 잠재적 데이터 경합!\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"fn main() {\n"
|
||||
" add_to_counter(42);\n"
|
||||
"\n"
|
||||
" unsafe { println!(\"COUNTER: {COUNTER}\"); } // 잠재적 데이터 경합!\n"
|
||||
"}\n"
|
||||
"```"
|
||||
|
||||
#: src/unsafe/mutable-static-variables.md:32
|
||||
msgid ""
|
||||
@ -10974,6 +10987,32 @@ msgid ""
|
||||
"}\n"
|
||||
"```"
|
||||
msgstr ""
|
||||
"```rust,editable\n"
|
||||
"fn main() {\n"
|
||||
" let emojis = \"🗻∈🌏\";\n"
|
||||
"\n"
|
||||
" // Safe because the indices are in the correct order, within the bounds "
|
||||
"of\n"
|
||||
" // the string slice, and lie on UTF-8 sequence boundaries.\n"
|
||||
" unsafe {\n"
|
||||
" println!(\"emoji: {}\", emojis.get_unchecked(0..4));\n"
|
||||
" println!(\"emoji: {}\", emojis.get_unchecked(4..7));\n"
|
||||
" println!(\"emoji: {}\", emojis.get_unchecked(7..11));\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" println!(\"char count: {}\", count_chars(unsafe { emojis."
|
||||
"get_unchecked(0..7) }));\n"
|
||||
"\n"
|
||||
" // Not upholding the UTF-8 encoding requirement breaks memory safety!\n"
|
||||
" // println!(\"emoji: {}\", unsafe { emojis.get_unchecked(0..3) });\n"
|
||||
" // println!(\"char count: {}\", count_chars(unsafe { emojis."
|
||||
"get_unchecked(0..3) }));\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"fn count_chars(s: &str) -> usize {\n"
|
||||
" s.chars().map(|_| 1).sum()\n"
|
||||
"}\n"
|
||||
"```"
|
||||
|
||||
#: src/unsafe/writing-unsafe-functions.md:1
|
||||
msgid "# Writing Unsafe Functions"
|
||||
|
Loading…
x
Reference in New Issue
Block a user