diff --git a/doc/po/ja/complement-bugreport.md.po b/doc/po/ja/complement-bugreport.md.po new file mode 100644 index 0000000000000..f36115333c9c2 --- /dev/null +++ b/doc/po/ja/complement-bugreport.md.po @@ -0,0 +1,118 @@ +# Japanese translations for Rust package +# Copyright (C) 2014 The Rust Project Developers +# This file is distributed under the same license as the Rust package. +# Automatically generated, 2014. +# +msgid "" +msgstr "" +"Project-Id-Version: Rust 0.9\n" +"POT-Creation-Date: 2014-01-10 12:20+0900\n" +"PO-Revision-Date: 2014-01-10 12:20+0900\n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: ja\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=1; plural=0;\n" + +#. type: Plain text +#: doc/complement-bugreport.md:2 +msgid "% HOWTO submit a RUST bug report" +msgstr "" + +#. type: Plain text +#: doc/complement-bugreport.md:4 +msgid "# I think I found a bug in the compiler!" +msgstr "" + +#. type: Plain text +#: doc/complement-bugreport.md:9 +#, no-wrap +msgid "" +" If you see this message: ''error: internal compiler error: unexpected failure'',\n" +"then you have definitely found a bug in the compiler. It's also possible that\n" +"your code is not well-typed, but if you saw this message, it's still a bug in\n" +"error reporting.\n" +msgstr "" + +#. type: Plain text +#: doc/complement-bugreport.md:13 +#, no-wrap +msgid "" +" If you see a message about an LLVM assertion failure, then you have also\n" +"definitely found a bug in the compiler. In both of these cases, it's not your\n" +"fault and you should report a bug!\n" +msgstr "" + +#. type: Plain text +#: doc/complement-bugreport.md:18 +#, no-wrap +msgid "" +" If you see a compiler error message that you think is meant for users to see,\n" +"but it confuses you, *that's a bug too*. If it wasn't clear to you, then it's\n" +"an error message we want to improve, so please report it so that we can try\n" +"to make it better.\n" +msgstr "" + +#. type: Plain text +#: doc/complement-bugreport.md:20 +msgid "" +"# I don't want to waste the Rust devs' time! How do I know the bug I found " +"isn't a bug that already exists in the issue tracker?" +msgstr "" + +#. type: Plain text +#: doc/complement-bugreport.md:25 +#, no-wrap +msgid "" +" If you don't have much time, then don't worry about that. Just submit the bug.\n" +"If it's a duplicate, somebody will notice that and close it. No one will laugh\n" +"at you, we promise (and if someone did, they would be violating the Rust\n" +"[code of conduct](https://github.com/mozilla/rust/wiki/Note-development-policy code of conduct)).\n" +msgstr "" + +#. type: Plain text +#: doc/complement-bugreport.md:33 +#, no-wrap +msgid "" +" If you have more time, it's very helpful if you can type the text of the error\n" +"message you got [into the issue tracker search box](https://github.com/mozilla/rust/issues)\n" +"to see if there's an existing bug that resembles your problem. If there is,\n" +"and it's an open bug, you can comment on that issue and say you ran into it too.\n" +"This will encourage devs to fix it. But again, don't let this stop you from\n" +"submitting a bug. We'd rather have to do the work of closing duplicates than\n" +"miss out on valid bug reports.\n" +msgstr "" + +#. type: Plain text +#: doc/complement-bugreport.md:35 +msgid "# What information should I include in a bug report?" +msgstr "" + +#. type: Plain text +#: doc/complement-bugreport.md:41 +#, no-wrap +msgid "" +" It's helpful to include your specific OS (for example: Mac OS X 10.8.3,\n" +"Windows 7, Ubuntu 12.0.4) and your hardware architecture (for example: i686, x86_64).\n" +"It's also helpful to copy/paste the output of re-running the erroneous rustc\n" +"commmand with the `-v` flag. Finally, if you can run the offending command under gdb,\n" +"pasting a stack trace can be useful; to do so, you will need to set a breakpoint on `rust_begin_unwind`.\n" +msgstr "" + +#. type: Plain text +#: doc/complement-bugreport.md:43 +msgid "# I submitted a bug, but nobody has commented on it! I'm sad." +msgstr "" + +#. type: Plain text +#: doc/complement-bugreport.md:48 +#, no-wrap +msgid "" +" This is sad, but does happen sometimes, since we're short-staffed. If you\n" +"submit a bug and you haven't received a comment on it within 3 business days,\n" +"it's entirely reasonable to either ask on the #rust IRC channel,\n" +"or post on the [rust-dev mailing list](https://mail.mozilla.org/listinfo/rust-dev)\n" +"to ask what the status of the bug is.\n" +msgstr "" diff --git a/doc/po/ja/complement-cheatsheet.md.po b/doc/po/ja/complement-cheatsheet.md.po new file mode 100644 index 0000000000000..2a9ae54ce8948 --- /dev/null +++ b/doc/po/ja/complement-cheatsheet.md.po @@ -0,0 +1,518 @@ +# Japanese translations for Rust package +# Copyright (C) 2014 The Rust Project Developers +# This file is distributed under the same license as the Rust package. +# Automatically generated, 2014. +# +msgid "" +msgstr "" +"Project-Id-Version: Rust 0.9\n" +"POT-Creation-Date: 2014-01-10 12:20+0900\n" +"PO-Revision-Date: 2014-01-10 12:20+0900\n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: ja\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=1; plural=0;\n" + +#. type: Plain text +#: doc/complement-cheatsheet.md:2 +msgid "% Rust Cheatsheet" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:4 +msgid "# How do I convert *X* to *Y*?" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:6 +#, no-wrap +msgid "**Int to string**\n" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:8 +msgid "" +"Use [`ToStr`](http://static.rust-lang.org/doc/master/std/to_str/trait.ToStr." +"html)." +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:13 +#, fuzzy +#| msgid "" +#| "~~~~ let x: f64 = 4.0; let y: uint = x as uint; assert!(y == 4u); ~~~~" +msgid "~~~ let x: int = 42; let y: ~str = x.to_str(); ~~~" +msgstr "" +"~~~~\n" +"let x: f64 = 4.0;\n" +"let y: uint = x as uint;\n" +"assert!(y == 4u);\n" +"~~~~" + +#. type: Plain text +#: doc/complement-cheatsheet.md:15 +#, no-wrap +msgid "**String to int**\n" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:17 +msgid "" +"Use [`FromStr`](http://static.rust-lang.org/doc/master/std/from_str/trait." +"FromStr.html), and its helper function, [`from_str`](http://static.rust-lang." +"org/doc/master/std/from_str/fn.from_str.html)." +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:22 +msgid "~~~ let x: Option = from_str(\"42\"); let y: int = x.unwrap(); ~~~" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:24 +#, no-wrap +msgid "**Int to string, in non-base-10**\n" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:26 +msgid "" +"Use [`ToStrRadix`](http://static.rust-lang.org/doc/master/std/num/trait." +"ToStrRadix.html)." +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:29 +#, fuzzy +#| msgid "~~~~ use std::task::spawn;" +msgid "~~~ use std::num::ToStrRadix;" +msgstr "" +"~~~~\n" +"use std::task::spawn;" + +#. type: Plain text +#: doc/complement-cheatsheet.md:33 +msgid "let x: int = 42; let y: ~str = x.to_str_radix(16); ~~~" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:35 +#, no-wrap +msgid "**String to int, in non-base-10**\n" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:37 +msgid "" +"Use [`FromStrRadix`](http://static.rust-lang.org/doc/master/std/num/trait." +"FromStrRadix.html), and its helper function, [`from_str_radix`](http://" +"static.rust-lang.org/doc/master/std/num/fn.from_str_radix.html)." +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:40 +#, fuzzy +#| msgid "~~~~ use std::task::spawn;" +msgid "~~~ use std::num::from_str_radix;" +msgstr "" +"~~~~\n" +"use std::task::spawn;" + +#. type: Plain text +#: doc/complement-cheatsheet.md:44 +msgid "" +"let x: Option = from_str_radix(\"deadbeef\", 16); let y: i64 = x." +"unwrap(); ~~~" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:46 +#, fuzzy +#| msgid "## Operators" +msgid "# File operations" +msgstr "## 演算子" + +#. type: Plain text +#: doc/complement-cheatsheet.md:48 +msgid "## How do I read from a file?" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:50 +msgid "" +"Use [`File::open`](http://static.rust-lang.org/doc/master/std/io/fs/struct." +"File.html#method.open) to create a [`File`](http://static.rust-lang.org/doc/" +"master/std/io/fs/struct.File.html) struct, which implements the [`Reader`]" +"(http://static.rust-lang.org/doc/master/std/io/trait.Reader.html) trait." +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:54 +msgid "~~~ {.xfail-test} use std::path::Path; use std::io::fs::File;" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:59 +#, no-wrap +msgid "" +"let path : Path = Path::new(\"Doc-FAQ-Cheatsheet.md\");\n" +"let on_error = || fail!(\"open of {:?} failed\", path);\n" +"let reader : File = File::open(&path).unwrap_or_else(on_error);\n" +"~~~\n" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:61 +msgid "## How do I iterate over the lines in a file?" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:63 +msgid "" +"Use the [`lines`](http://static.rust-lang.org/doc/master/std/io/trait.Buffer." +"html#method.lines) method on a [`BufferedReader`](http://static.rust-lang." +"org/doc/master/std/io/buffered/struct.BufferedReader.html)." +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:67 +msgid "" +"~~~ use std::io::buffered::BufferedReader; # use std::io::mem::MemReader;" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:69 +msgid "# let reader = MemReader::new(~[]);" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:75 +#, no-wrap +msgid "" +"let mut reader = BufferedReader::new(reader);\n" +"for line in reader.lines() {\n" +" print!(\"line: {}\", line);\n" +"}\n" +"~~~\n" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:77 +#, fuzzy +#| msgid "## Using other crates" +msgid "# String operations" +msgstr "## 他のクレートの利用" + +#. type: Plain text +#: doc/complement-cheatsheet.md:79 +msgid "## How do I search for a substring?" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:81 +msgid "" +"Use the [`find_str`](http://static.rust-lang.org/doc/master/std/str/trait." +"StrSlice.html#tymethod.find_str) method." +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:86 +msgid "" +"~~~ let str = \"Hello, this is some random string\"; let index: Option " +"= str.find_str(\"rand\"); ~~~" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:88 doc/guide-container.md:4 +#, fuzzy +#| msgid "## Conventions" +msgid "# Containers" +msgstr "## 本書の表記について" + +#. type: Plain text +#: doc/complement-cheatsheet.md:90 +msgid "## How do I get the length of a vector?" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:92 +msgid "" +"The [`Container`](http://static.rust-lang.org/doc/master/std/container/trait." +"Container.html) trait provides the `len` method." +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:97 +msgid "" +"~~~ let u: ~[u32] = ~[0, 1, 2]; let v: &[u32] = &[0, 1, 2, 3]; let w: " +"[u32, .. 5] = [0, 1, 2, 3, 4];" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:100 +msgid "" +"println!(\"u: {}, v: {}, w: {}\", u.len(), v.len(), w.len()); // 3, 4, 5 ~~~" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:102 +msgid "## How do I iterate over a vector?" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:104 +msgid "" +"Use the [`iter`](http://static.rust-lang.org/doc/master/std/vec/trait." +"ImmutableVector.html#tymethod.iter) method." +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:111 +#, no-wrap +msgid "" +"~~~\n" +"let values: ~[int] = ~[1, 2, 3, 4, 5];\n" +"for value in values.iter() { // value: &int\n" +" println!(\"{}\", *value);\n" +"}\n" +"~~~\n" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:113 +msgid "" +"(See also [`mut_iter`](http://static.rust-lang.org/doc/master/std/vec/trait." +"MutableVector.html#tymethod.mut_iter) which yields `&mut int` and " +"[`move_iter`](http://static.rust-lang.org/doc/master/std/vec/trait." +"OwnedVector.html#tymethod.move_iter) which yields `int` while consuming the " +"`values` vector.)" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:115 doc/rust.md:2970 +msgid "# Type system" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:117 +msgid "## How do I store a function in a struct?" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:122 +#, no-wrap +msgid "" +"~~~\n" +"struct Foo {\n" +" myfunc: fn(int, uint) -> i32\n" +"}\n" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:126 +#, no-wrap +msgid "" +"struct FooClosure<'a> {\n" +" myfunc: 'a |int, uint| -> i32\n" +"}\n" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:130 +#, no-wrap +msgid "" +"fn a(a: int, b: uint) -> i32 {\n" +" (a as uint + b) as i32\n" +"}\n" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:138 +#, no-wrap +msgid "" +"fn main() {\n" +" let f = Foo { myfunc: a };\n" +" let g = FooClosure { myfunc: |a, b| { (a - b as int) as i32 } };\n" +" println!(\"{}\", (f.myfunc)(1, 2));\n" +" println!(\"{}\", (g.myfunc)(3, 4));\n" +"}\n" +"~~~\n" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:140 +msgid "" +"Note that the parenthesis surrounding `f.myfunc` are necessary: they are how " +"Rust disambiguates field lookup and method call. The `'a` on `FooClosure` is " +"the lifetime of the closure's environment pointer." +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:142 +msgid "## How do I express phantom types?" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:144 +msgid "" +"[Phantom types](http://www.haskell.org/haskellwiki/Phantom_type) are those " +"that cannot be constructed at compile time. To express these in Rust, zero-" +"variant `enum`s can be used:" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:149 +msgid "~~~ enum Open {} enum Closed {} ~~~" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:151 +msgid "" +"Phantom types are useful for enforcing state at compile time. For example:" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:154 +msgid "~~~ struct Door(~str);" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:157 +msgid "struct Open; struct Closed;" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:161 +#, no-wrap +msgid "" +"fn close(Door(name): Door) -> Door {\n" +" Door::(name)\n" +"}\n" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:165 +#, no-wrap +msgid "" +"fn open(Door(name): Door) -> Door {\n" +" Door::(name)\n" +"}\n" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:168 +msgid "let _ = close(Door::(~\"front\")); ~~~" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:170 +msgid "Attempting to close a closed door is prevented statically:" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:174 +msgid "" +"~~~ {.xfail-test} let _ = close(Door::(~\"front\")); // error: " +"mismatched types: expected `main::Door` but found `main::" +"Door` ~~~" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:176 +#, fuzzy +#| msgid "[The foreign function interface][ffi]" +msgid "# FFI (Foreign Function Interface)" +msgstr "[他言語間インターフェース (foreign function inferface)][ffi]" + +#. type: Plain text +#: doc/complement-cheatsheet.md:178 +msgid "## C function signature conversions" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:185 +#, no-wrap +msgid "" +"Description C signature Equivalent Rust signature\n" +"---------------------- ---------------------------------------------- ------------------------------------------\n" +"no parameters `void foo(void);` `fn foo();`\n" +"return value `int foo(void);` `fn foo() -> c_int;`\n" +"function parameters `void foo(int x, int y);` `fn foo(x: int, y: int);`\n" +"in-out pointers `void foo(const int* in_ptr, int* out_ptr);` `fn foo(in_ptr: *c_int, out_ptr: *mut c_int);`\n" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:187 +msgid "" +"Note: The Rust signatures should be wrapped in an `extern \"ABI\" { ... }` " +"block." +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:189 +msgid "### Representing opaque handles" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:191 +msgid "You might see things like this in C APIs:" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:196 +msgid "" +"~~~ {.notrust} typedef struct Window Window; Window* createWindow(int width, " +"int height); ~~~" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:198 +msgid "" +"You can use a zero-element `enum` ([phantom type](#how-do-i-express-phantom-" +"types)) to represent the opaque object handle. The FFI would look like this:" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:205 +#, no-wrap +msgid "" +"~~~ {.xfail-test}\n" +"enum Window {}\n" +"extern \"C\" {\n" +" fn createWindow(width: c_int, height: c_int) -> *Window;\n" +"}\n" +"~~~\n" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:207 +msgid "" +"Using a phantom type ensures that the handles cannot be (safely) constructed " +"in client code." +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:209 +msgid "# Contributing to this page" +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:211 +msgid "" +"For small examples, have full type annotations, as much as is reasonable, to " +"keep it clear what, exactly, everything is doing. Try to link to the API " +"docs, as well." +msgstr "" + +#. type: Plain text +#: doc/complement-cheatsheet.md:213 +msgid "Similar documents for other programming languages:" +msgstr "" + +#. type: Bullet: ' * ' +#: doc/complement-cheatsheet.md:214 +msgid "[http://pleac.sourceforge.net/](http://pleac.sourceforge.net)" +msgstr "" diff --git a/doc/po/ja/complement-lang-faq.md.po b/doc/po/ja/complement-lang-faq.md.po new file mode 100644 index 0000000000000..3d366255390c5 --- /dev/null +++ b/doc/po/ja/complement-lang-faq.md.po @@ -0,0 +1,877 @@ +# Japanese translations for Rust package +# Copyright (C) 2014 The Rust Project Developers +# This file is distributed under the same license as the Rust package. +# Automatically generated, 2014. +# +msgid "" +msgstr "" +"Project-Id-Version: Rust 0.9\n" +"POT-Creation-Date: 2014-01-10 12:20+0900\n" +"PO-Revision-Date: 2014-01-10 12:20+0900\n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: ja\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=1; plural=0;\n" + +#. type: Plain text +#: doc/complement-lang-faq.md:2 +msgid "% Language FAQ" +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:4 +msgid "# General language issues" +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:6 +msgid "## Safety oriented" +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:12 +msgid "" +"Memory safe: no null pointers, dangling pointers, use-before-initialize or " +"use-after-move" +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:12 +msgid "" +"Expressive mutability control. Immutable by default, statically verified " +"freezing for Owned types" +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:12 +msgid "No shared mutable state across tasks" +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:12 +msgid "" +"Dynamic execution safety: task failure / unwinding, trapping, RAII / dtors" +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:12 +msgid "Safe interior pointer types with lifetime analysis" +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:14 +msgid "## Concurrency and efficiency oriented" +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:21 +msgid "Lightweight tasks (coroutines) with expanding stacks" +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:21 +msgid "Fast asynchronous, copyless message passing" +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:21 +msgid "Optional garbage collected pointers" +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:21 +msgid "" +"All types may be explicitly allocated on the stack or interior to other types" +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:21 +msgid "Static, native compilation using LLVM" +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:21 +msgid "Direct and simple interface to C code" +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:23 +msgid "## Practicality oriented" +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:33 +#, no-wrap +msgid "" +"* Multi-paradigm: pure-functional, concurrent-actor, imperative-procedural, OO\n" +" * First-class functions, cheap non-escaping closures\n" +" * Algebraic data types (called enums) with pattern matching\n" +" * Method implementations on any type\n" +" * Traits, which share aspects of type classes and interfaces\n" +"* Multi-platform. Developed on Windows, Linux, OS X\n" +"* UTF-8 strings, assortment of machine-level types\n" +"* Works with existing native toolchains, GDB, Valgrind, Instruments, etc\n" +"* Rule-breaking is allowed if explicit about where and how\n" +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:35 +msgid "## What does it look like?" +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:37 +msgid "" +"The syntax is still evolving, but here's a snippet from the hash map in " +"core::hashmap." +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:46 +#, no-wrap +msgid "" +"~~~\n" +"struct LinearMap {\n" +" k0: u64,\n" +" k1: u64,\n" +" resize_at: uint,\n" +" size: uint,\n" +" buckets: ~[Option>],\n" +"}\n" +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:50 +#, no-wrap +msgid "" +"enum SearchResult {\n" +" FoundEntry(uint), FoundHole(uint), TableFull\n" +"}\n" +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:55 +#, no-wrap +msgid "" +"fn linear_map_with_capacity(capacity: uint) -> LinearMap {\n" +" let r = rand::Rng();\n" +" linear_map_with_capacity_and_keys(r.gen_u64(), r.gen_u64(), capacity)\n" +"}\n" +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:57 +msgid "impl LinearMap {" +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:64 +#, no-wrap +msgid "" +" fn contains_key(&self, k: &K) -> bool {\n" +" match self.bucket_for_key(self.buckets, k) {\n" +" FoundEntry(_) => true,\n" +" TableFull | FoundHole(_) => false\n" +" }\n" +" }\n" +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:71 +#, no-wrap +msgid "" +" fn clear(&mut self) {\n" +" for bkt in self.buckets.mut_iter() {\n" +" *bkt = None;\n" +" }\n" +" self.size = 0;\n" +" }\n" +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:75 +msgid "... } ~~~" +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:77 +msgid "" +"## Are there any big programs written in it yet? I want to read big samples." +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:79 +msgid "" +"There aren't many large programs yet. The Rust [compiler][rustc], 60,000+ " +"lines at the time of writing, is written in Rust. As the oldest body of Rust " +"code it has gone through many iterations of the language, and some parts are " +"nicer to look at than others. It may not be the best code to learn from, but " +"[borrowck] and [resolve] were written recently." +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:83 +msgid "" +"[rustc]: https://github.com/mozilla/rust/tree/master/src/librustc [resolve]: " +"https://github.com/mozilla/rust/blob/master/src/librustc/middle/resolve.rs " +"[borrowck]: https://github.com/mozilla/rust/blob/master/src/librustc/middle/" +"borrowck/" +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:85 +msgid "" +"A research browser engine called [Servo][servo], currently 30,000+ lines " +"across more than a dozen crates, will be exercising a lot of Rust's " +"distinctive type-system and concurrency features, and integrating many " +"native libraries." +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:87 +msgid "[servo]: https://github.com/mozilla/servo" +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:89 +msgid "Some examples that demonstrate different aspects of the language:" +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:94 +msgid "" +"[sprocketnes], an NES emulator with no GC, using modern Rust conventions" +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:94 +msgid "" +"The language's general-purpose [hash] function, SipHash-2-4. Bit twiddling, " +"OO, macros" +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:94 +msgid "The standard library's [HashMap], a sendable hash map in an OO style" +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:94 +msgid "The extra library's [json] module. Enums and pattern matching" +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:99 +msgid "" +"[sprocketnes]: https://github.com/pcwalton/sprocketnes [hash]: https://" +"github.com/mozilla/rust/blob/master/src/libstd/hash.rs [HashMap]: https://" +"github.com/mozilla/rust/blob/master/src/libstd/hashmap.rs [json]: https://" +"github.com/mozilla/rust/blob/master/src/libextra/json.rs" +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:101 +msgid "" +"You may also be interested in browsing [GitHub's Rust][github-rust] page." +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:103 +msgid "[github-rust]: https://github.com/languages/Rust" +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:105 +msgid "## Does it run on Windows?" +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:107 +msgid "" +"Yes. All development happens in lock-step on all 3 target platforms. Using " +"MinGW, not Cygwin. Note that the windows implementation currently has some " +"limitations: in particular tasks [cannot unwind on windows][unwind], and all " +"Rust executables [require a MinGW installation at runtime][libgcc]." +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:110 +#, fuzzy +#| msgid "" +#| "[bug-3319]: https://github.com/mozilla/rust/issues/3319 [wiki-start]: " +#| "https://github.com/mozilla/rust/wiki/Note-getting-started-developing-Rust" +msgid "" +"[unwind]: https://github.com/mozilla/rust/issues/908 [libgcc]: https://" +"github.com/mozilla/rust/issues/1603" +msgstr "" +"[bug-3319]: https://github.com/mozilla/rust/issues/3319\n" +"[wiki-start]: https://github.com/mozilla/rust/wiki/Note-getting-started-" +"developing-Rust" + +#. type: Plain text +#: doc/complement-lang-faq.md:112 +msgid "## Have you seen this Google language, Go? How does Rust compare?" +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:114 +msgid "" +"Rust and Go have similar syntax and task models, but they have very " +"different type systems. Rust is distinguished by greater type safety and " +"memory safety guarantees, more control over memory layout, and robust " +"generics." +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:116 +msgid "Rust has several key features that aren't shared by Go:" +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:121 +msgid "" +"No shared mutable state - Shared mutable state allows data races, a large " +"class of bad bugs. In Rust there is no sharing of mutable data, but " +"ownership of data can be efficiently transferred between tasks." +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:121 +msgid "" +"Minimal GC impact - By not having shared mutable data, Rust can avoid global " +"GC, hence Rust never stops the world to collect garbage. With multiple " +"allocation options, individual tasks can completely avoid GC." +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:121 +msgid "" +"No null pointers - Accidentally dereferencing null pointers is a big bummer, " +"so Rust doesn't have them." +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:121 +msgid "" +"Type parametric code - Generics prove useful time and again, though they are " +"inevitably complex to greater or lesser degrees." +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:123 +msgid "" +"Some of Rust's advantages come at the cost of a more intricate type system " +"than Go's." +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:125 +msgid "" +"Go has its own strengths and in particular has a great user experience that " +"Rust still lacks." +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:127 +msgid "## I like the language but it really needs _$somefeature_." +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:129 +msgid "" +"At this point we are focusing on removing and stabilizing features rather " +"than adding them. File a bug if you think it's important in terms of meeting " +"the existing goals or making the language passably usable. Reductions are " +"more interesting than additions, though." +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:131 +msgid "# Specific language issues" +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:133 +msgid "## Is it OO? How do I do this thing I normally do in an OO language?" +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:135 +msgid "" +"It is multi-paradigm. Not everything is shoe-horned into a single " +"abstraction. Many things you can do in OO languages you can do in Rust, but " +"not everything, and not always using the same abstraction you're accustomed " +"to." +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:137 +msgid "## How do you get away with \"no null pointers\"?" +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:139 +msgid "" +"Data values in the language can only be constructed through a fixed set of " +"initializer forms. Each of those forms requires that its inputs already be " +"initialized. A liveness analysis ensures that local variables are " +"initialized before use." +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:141 +msgid "## What is the relationship between a module and a crate?" +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:149 +msgid "" +"A crate is a top-level compilation unit that corresponds to a single " +"loadable object." +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:149 +msgid "A module is a (possibly nested) unit of name-management inside a crate." +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:149 +msgid "A crate contains an implicit, un-named top-level module." +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:149 +msgid "Recursive definitions can span modules, but not crates." +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:149 +msgid "" +"Crates do not have global names, only a set of non-unique metadata tags." +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:149 +#, no-wrap +msgid "" +"* There is no global inter-crate namespace; all name management occurs within a crate.\n" +" * Using another crate binds the root of _its_ namespace into the user's namespace.\n" +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:151 +msgid "" +"## Why is failure unwinding non-recoverable within a task? Why not try to " +"\"catch exceptions\"?" +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:153 +msgid "" +"In short, because too few guarantees could be made about the dynamic " +"environment of the catch block, as well as invariants holding in the unwound " +"heap, to be able to safely resume; we believe that other methods of " +"signalling and logging errors are more appropriate, with tasks playing the " +"role of a \"hard\" isolation boundary between separate heaps." +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:155 +msgid "" +"Rust provides, instead, three predictable and well-defined options for " +"handling any combination of the three main categories of \"catch\" logic:" +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:159 +msgid "Failure _logging_ is done by the integrated logging subsystem." +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:159 +msgid "" +"_Recovery_ after a failure is done by trapping a task failure from _outside_ " +"the task, where other tasks are known to be unaffected." +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:159 +msgid "_Cleanup_ of resources is done by RAII-style objects with destructors." +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:161 +msgid "" +"Cleanup through RAII-style destructors is more likely to work than in catch " +"blocks anyways, since it will be better tested (part of the non-error " +"control paths, so executed all the time)." +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:163 +msgid "## Why aren't modules type-parametric?" +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:165 +msgid "" +"We want to maintain the option to parametrize at runtime. We may make " +"eventually change this limitation, but initially this is how type parameters " +"were implemented." +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:167 +msgid "## Why aren't values type-parametric? Why only items?" +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:169 +msgid "" +"Doing so would make type inference much more complex, and require the " +"implementation strategy of runtime parametrization." +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:171 +msgid "## Why are enumerations nominal and closed?" +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:173 +msgid "" +"We don't know if there's an obvious, easy, efficient, stock-textbook way of " +"supporting open or structural disjoint unions. We prefer to stick to " +"language features that have an obvious and well-explored semantics." +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:175 +msgid "## Why aren't channels synchronous?" +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:177 +msgid "" +"There's a lot of debate on this topic; it's easy to find a proponent of " +"default-sync or default-async communication, and there are good reasons for " +"either. Our choice rests on the following arguments:" +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:181 +msgid "" +"Part of the point of isolating tasks is to decouple tasks from one another, " +"such that assumptions in one task do not cause undue constraints (or bugs, " +"if violated!) in another. Temporal coupling is as real as any other kind; " +"async-by-default relaxes the default case to only _causal_ coupling." +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:181 +msgid "" +"Default-async supports buffering and batching communication, reducing the " +"frequency and severity of task-switching and inter-task / inter-domain " +"synchronization." +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:181 +msgid "" +"Default-async with transmittable channels is the lowest-level building block " +"on which more-complex synchronization topologies and strategies can be " +"built; it is not clear to us that the majority of cases fit the 2-party full-" +"synchronization pattern rather than some more complex multi-party or multi-" +"stage scenario. We did not want to force all programs to pay for wiring the " +"former assumption into all communications." +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:183 +msgid "## Why are channels half-duplex (one-way)?" +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:185 +msgid "" +"Similar to the reasoning about default-sync: it wires fewer assumptions into " +"the implementation, that would have to be paid by all use-cases even if they " +"actually require a more complex communication topology." +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:187 +msgid "## Why are strings UTF-8 by default? Why not UCS2 or UCS4?" +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:189 +msgid "" +"The `str` type is UTF-8 because we observe more text in the wild in this " +"encoding -- particularly in network transmissions, which are endian-agnostic " +"-- and we think it's best that the default treatment of I/O not involve " +"having to recode codepoints in each direction." +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:191 +msgid "" +"This does mean that indexed access to a Unicode codepoint inside a `str` " +"value is an O(n) operation. On the one hand, this is clearly undesirable; on " +"the other hand, this problem is full of trade-offs and we'd like to point a " +"few important qualifications:" +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:195 +msgid "" +"Scanning a `str` for ASCII-range codepoints can still be done safely octet-" +"at-a-time, with each indexing operation pulling out a `u8` costing only O(1) " +"and producing a value that can be cast and compared to an ASCII-range " +"`char`. So if you're (say) line-breaking on `'\\n'`, octet-based treatment " +"still works. UTF8 was well-designed this way." +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:195 +msgid "" +"Most \"character oriented\" operations on text only work under very " +"restricted language assumptions sets such as \"ASCII-range codepoints only" +"\". Outside ASCII-range, you tend to have to use a complex (non-constant-" +"time) algorithm for determining linguistic-unit (glyph, word, paragraph) " +"boundaries anyways. We recommend using an \"honest\" linguistically-aware, " +"Unicode-approved algorithm." +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:195 +msgid "" +"The `char` type is UCS4. If you honestly need to do a codepoint-at-a-time " +"algorithm, it's trivial to write a `type wstr = [char]`, and unpack a `str` " +"into it in a single pass, then work with the `wstr`. In other words: the " +"fact that the language is not \"decoding to UCS4 by default\" shouldn't stop " +"you from decoding (or re-encoding any other way) if you need to work with " +"that encoding." +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:197 +msgid "" +"## Why are strings, vectors etc. built-in types rather than (say) special " +"kinds of trait/impl?" +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:199 +msgid "" +"In each case there is one or more operator, literal constructor, overloaded " +"use or integration with a built-in control structure that makes us think it " +"would be awkward to phrase the type in terms of more-general type " +"constructors. Same as, say, with numbers! But this is partly an aesthetic " +"call, and we'd be willing to look at a worked-out proposal for eliminating " +"or rephrasing these special cases." +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:201 +msgid "## Can Rust code call C code?" +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:203 +msgid "" +"Yes. Since C code typically expects a larger stack than Rust code does, the " +"stack may grow before the call. The Rust domain owning the task that makes " +"the call will block for the duration of the call, so if the call is likely " +"to be long-lasting, you should consider putting the task in its own domain " +"(thread or process)." +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:205 +msgid "## Can C code call Rust code?" +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:207 +msgid "" +"Yes. The Rust code has to be exposed via an `extern` declaration, which " +"makes it C-ABI compatible. Its address can then be taken and passed to C " +"code. When C calls Rust back, the callback occurs in very restricted " +"circumstances." +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:209 +msgid "## How do Rust's task stacks work?" +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:211 +msgid "" +"They start small (ideally in the hundreds of bytes) and expand dynamically " +"by calling through special frames that allocate new stack segments. This is " +"known as the \"spaghetti stack\" approach." +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:213 +msgid "" +"## What is the difference between a managed box pointer (`@`) and an owned " +"box pointer (`~`)?" +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:220 +msgid "Managed boxes live in the garbage collected task-local heap" +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:220 +msgid "Owned boxes live in the global exchange heap" +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:220 +msgid "Managed boxes may be referred to by multiple managed box references" +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:220 +msgid "" +"Owned boxes have unique ownership and there may only be a single unique " +"pointer to a unique box at a time" +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:220 +msgid "Managed boxes may not be shared between tasks" +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:220 +msgid "Owned boxes may be transferred (moved) between tasks" +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:222 +msgid "" +"## What is the difference between a reference (`&`) and managed and owned " +"boxes?" +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:228 +msgid "References point to the interior of a stack _or_ heap allocation" +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:228 +msgid "" +"References can only be formed when it will provably be outlived by the " +"referent" +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:228 +msgid "References to managed box pointers keep the managed boxes alive" +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:228 +msgid "" +"References to owned boxes prevent their ownership from being transferred" +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:228 +msgid "References employ region-based alias analysis to ensure correctness" +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:230 +msgid "## Why aren't function signatures inferred? Why only local slots?" +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:234 +msgid "" +"Mechanically, it simplifies the inference algorithm; inference only requires " +"looking at one function at a time." +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:234 +msgid "" +"The same simplification goes double for human readers. A reader does not " +"need an IDE running an inference algorithm across an entire crate to be able " +"to guess at a function's argument types; it's always explicit and nearby." +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:234 +msgid "" +"Parameters in Rust can be passed by reference or by value. We can't " +"automatically infer which one the programmer means." +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:236 +msgid "" +"## Why does a type parameter need explicit trait bounds to invoke methods on " +"it, when C++ templates do not?" +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:238 +msgid "" +"Requiring explicit bounds means that the compiler can type-check the code at " +"the point where the type-parametric item is *defined*, rather than delaying " +"to when its type parameters are instantiated. You know that *any* set of " +"type parameters fulfilling the bounds listed in the API will compile. It's " +"an enforced minimal level of documentation, and results in very clean error " +"messages." +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:240 +msgid "" +"Scoping of methods is also a problem. C++ needs [Koenig (argument " +"dependent) lookup](http://en.wikipedia.org/wiki/Argument-" +"dependent_name_lookup), which comes with its own host of problems. Explicit " +"bounds avoid this issue: traits are explicitly imported and then used as " +"bounds on type parameters, so there is a clear mapping from the method to " +"its implementation (via the trait and the instantiated type)." +msgstr "" + +#. type: Bullet: ' * ' +#: doc/complement-lang-faq.md:242 +msgid "" +"Related to the above point: since a parameter explicitly names its trait " +"bounds, a single type is able to implement traits whose sets of method names " +"overlap, cleanly and unambiguously." +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-lang-faq.md:244 +msgid "" +"There is further discussion on [this thread on the Rust mailing list]" +"(https://mail.mozilla.org/pipermail/rust-dev/2013-September/005603.html)." +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:246 +msgid "## Will Rust implement automatic semicolon insertion, like in Go?" +msgstr "" + +#. type: Plain text +#: doc/complement-lang-faq.md:247 +msgid "" +"For simplicity, we do not plan to do so. Implementing automatic semicolon " +"insertion for Rust would be tricky because the absence of a trailing " +"semicolon means \"return a value\"." +msgstr "" diff --git a/doc/po/ja/complement-project-faq.md.po b/doc/po/ja/complement-project-faq.md.po new file mode 100644 index 0000000000000..dd1382c73ebe5 --- /dev/null +++ b/doc/po/ja/complement-project-faq.md.po @@ -0,0 +1,290 @@ +# Japanese translations for Rust package +# Copyright (C) 2014 The Rust Project Developers +# This file is distributed under the same license as the Rust package. +# Automatically generated, 2014. +# +msgid "" +msgstr "" +"Project-Id-Version: Rust 0.9\n" +"POT-Creation-Date: 2014-01-10 12:20+0900\n" +"PO-Revision-Date: 2014-01-10 12:20+0900\n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: ja\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=1; plural=0;\n" + +#. type: Plain text +#: doc/complement-project-faq.md:2 +msgid "% Project FAQ" +msgstr "" + +#. type: Plain text +#: doc/complement-project-faq.md:4 +msgid "# What is this project's goal, in one sentence?" +msgstr "" + +#. type: Plain text +#: doc/complement-project-faq.md:6 +msgid "" +"To design and implement a safe, concurrent, practical, static systems " +"language." +msgstr "" + +#. type: Plain text +#: doc/complement-project-faq.md:8 +msgid "# Why are you doing this?" +msgstr "" + +#. type: Plain text +#: doc/complement-project-faq.md:10 +msgid "" +"Existing languages at this level of abstraction and efficiency are " +"unsatisfactory. In particular:" +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-project-faq.md:14 +msgid "Too little attention paid to safety." +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-project-faq.md:14 +msgid "Poor concurrency support." +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-project-faq.md:14 +msgid "Lack of practical affordances, too dogmatic about paradigm." +msgstr "" + +#. type: Plain text +#: doc/complement-project-faq.md:16 +msgid "# What are some non-goals?" +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-project-faq.md:23 +msgid "" +"To employ any particularly cutting-edge technologies. Old, established " +"techniques are better." +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-project-faq.md:23 +msgid "" +"To prize expressiveness, minimalism or elegance above other goals. These are " +"desirable but subordinate goals." +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-project-faq.md:23 +msgid "" +"To cover the \"systems language\" part all the way down to \"writing an OS " +"kernel\"." +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-project-faq.md:23 +msgid "" +"To cover the complete feature-set of C++, or any other language. It should " +"provide majority-case features." +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-project-faq.md:23 +msgid "" +"To be 100% static, 100% safe, 100% reflective, or too dogmatic in any other " +"sense. Trade-offs exist." +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-project-faq.md:23 +msgid "" +"To run on \"every possible platform\". It must eventually work without " +"unnecessary compromises on widely-used hardware and software platforms." +msgstr "" + +#. type: Plain text +#: doc/complement-project-faq.md:25 +msgid "# Is any part of this thing production-ready?" +msgstr "" + +#. type: Plain text +#: doc/complement-project-faq.md:27 +msgid "" +"No. Feel free to play around, but don't expect completeness or stability " +"yet. Expect incompleteness and breakage." +msgstr "" + +#. type: Plain text +#: doc/complement-project-faq.md:29 +msgid "What exists presently is:" +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-project-faq.md:36 +msgid "A self-hosted (written in Rust) compiler, which uses LLVM as a backend." +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-project-faq.md:36 +msgid "A runtime library." +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-project-faq.md:36 +#, fuzzy +#| msgid "## The standard library" +msgid "An evolving standard library." +msgstr "## 標準ライブラリ" + +#. type: Bullet: '* ' +#: doc/complement-project-faq.md:36 +msgid "Documentation for the language and libraries." +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-project-faq.md:36 +msgid "Incomplete tools for packaging and documentation." +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-project-faq.md:36 +msgid "A test suite covering the compiler and libraries." +msgstr "" + +#. type: Plain text +#: doc/complement-project-faq.md:38 +msgid "# Is this a completely Mozilla-planned and orchestrated thing?" +msgstr "" + +#. type: Plain text +#: doc/complement-project-faq.md:40 +msgid "" +"No. It started as a part-time side project in 2006 and remained so for over " +"3 years. Mozilla got involved in 2009 once the language was mature enough to " +"run some basic tests and demonstrate the idea." +msgstr "" + +#. type: Plain text +#: doc/complement-project-faq.md:42 +msgid "# Why did you do so much work in private?" +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-project-faq.md:45 +msgid "" +"A certain amount of shyness. Language work is somewhat political and flame-" +"inducing." +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-project-faq.md:45 +msgid "" +"Languages designed by committee have a poor track record. Design coherence " +"is important. There were a lot of details to work out and the initial " +"developer (Graydon) had this full time job thing eating up most days." +msgstr "" + +#. type: Plain text +#: doc/complement-project-faq.md:47 +msgid "# Why publish it now?" +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-project-faq.md:50 +msgid "" +"The design is stable enough. All the major pieces have reached non-" +"imaginary, initial implementation status. It seems to hold together ok." +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-project-faq.md:50 +msgid "" +"Languages solely implemented and supported by one person _also_ have a poor " +"track record. To survive it'll need help." +msgstr "" + +#. type: Plain text +#: doc/complement-project-faq.md:52 +msgid "# What will Mozilla use Rust for?" +msgstr "" + +#. type: Plain text +#: doc/complement-project-faq.md:54 +msgid "" +"Mozilla intends to use Rust as a platform for prototyping experimental " +"browser architectures. Specifically, the hope is to develop a browser that " +"is more amenable to parallelization than existing ones, while also being " +"less prone to common C++ coding errors. The name of that project is _[Servo]" +"(http://github.com/mozilla/servo)_." +msgstr "" + +#. type: Plain text +#: doc/complement-project-faq.md:56 +msgid "" +"# Are you going to use this to suddenly rewrite the browser and change " +"everything? Is the Mozilla Corporation trying to force the community to use " +"a new language?" +msgstr "" + +#. type: Plain text +#: doc/complement-project-faq.md:58 +msgid "" +"No. This is a research project. The point is to explore ideas. There is no " +"plan to incorporate any Rust-based technology into Firefox." +msgstr "" + +#. type: Plain text +#: doc/complement-project-faq.md:60 +msgid "" +"# Why GitHub rather than the normal Mozilla setup (Mercurial / Bugzilla / " +"Tinderbox)?" +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-project-faq.md:64 +msgid "" +"This is a fresh codebase and has no existing ties to Mozilla infrastructure; " +"there is no particular advantage to (re)using any of the above " +"infrastructure, it would all have to be upgraded and adapted to our needs." +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-project-faq.md:64 +msgid "" +"Git has been progressing rapidly in the years since Mozilla picked Mercurial " +"for its main development needs, and appears to be both more widely known and " +"more accessible at this point." +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-project-faq.md:64 +msgid "" +"This reduces the administrative requirements for contributing to merely " +"establishing a paper trail via a contributor agreement. There is no need for " +"vouching, granting commit access to Mozilla facilities, or setting up " +"Mozilla user accounts." +msgstr "" + +#. type: Plain text +#: doc/complement-project-faq.md:66 +msgid "# Why a BSD-style license rather than MPL or tri-license?" +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-project-faq.md:68 +msgid "Partly due to preference of the original developer (Graydon)." +msgstr "" + +#. type: Bullet: '* ' +#: doc/complement-project-faq.md:68 +msgid "" +"Partly due to the fact that languages tend to have a wider audience and more " +"diverse set of possible embeddings and end-uses than focused, coherent " +"products such as web browsers. We'd like to appeal to as many of those " +"potential contributors as possible." +msgstr "" diff --git a/doc/po/ja/complement-usage-faq.md.po b/doc/po/ja/complement-usage-faq.md.po new file mode 100644 index 0000000000000..2df172aaf0797 --- /dev/null +++ b/doc/po/ja/complement-usage-faq.md.po @@ -0,0 +1,121 @@ +# Japanese translations for Rust package +# Copyright (C) 2014 The Rust Project Developers +# This file is distributed under the same license as the Rust package. +# Automatically generated, 2014. +# +msgid "" +msgstr "" +"Project-Id-Version: Rust 0.9\n" +"POT-Creation-Date: 2014-01-10 12:20+0900\n" +"PO-Revision-Date: 2014-01-10 12:20+0900\n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: ja\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=1; plural=0;\n" + +#. type: Plain text +#: doc/complement-usage-faq.md:2 +msgid "% Usage FAQ" +msgstr "" + +#. type: Plain text +#: doc/complement-usage-faq.md:4 +msgid "# How do I get my program to display the output of `log` statements?" +msgstr "" + +#. type: Plain text +#: doc/complement-usage-faq.md:6 +#, no-wrap +msgid "**Short answer** set the RUST_LOG environment variable to the name of your source file, sans extension.\n" +msgstr "" + +#. type: Plain text +#: doc/complement-usage-faq.md:12 +msgid "```sh rustc hello.rs export RUST_LOG=hello ./hello ```" +msgstr "" + +#. type: Plain text +#: doc/complement-usage-faq.md:14 +#, no-wrap +msgid "**Long answer** RUST_LOG takes a 'logging spec' that consists of a comma-separated list of paths, where a path consists of the crate name and sequence of module names, each separated by double-colons. For standalone .rs files the crate is implicitly named after the source file, so in the above example we were setting RUST_LOG to the name of the hello crate. Multiple paths can be combined to control the exact logging you want to see. For example, when debugging linking in the compiler you might set `RUST_LOG=rustc::metadata::creader,rustc::util::filesearch,rustc::back::rpath`\n" +msgstr "" + +#. type: Plain text +#: doc/complement-usage-faq.md:16 +msgid "" +"If you aren't sure which paths you need, try setting RUST_LOG to `::help` " +"and running your program. This will print a list of paths available for " +"logging. For a full description see [the language reference][1]." +msgstr "" + +#. type: Plain text +#: doc/complement-usage-faq.md:18 +msgid "[1]:http://doc.rust-lang.org/doc/master/rust.html#logging-system" +msgstr "" + +#. type: Plain text +#: doc/complement-usage-faq.md:20 +msgid "# How do I get my program to display the output of `debug!` statements?" +msgstr "" + +#. type: Plain text +#: doc/complement-usage-faq.md:22 +msgid "" +"This is much like the answer for `log` statements, except that you also need " +"to compile your program in debug mode (that is, pass `--cfg debug` to " +"`rustc`). Note that if you want to see the instrumentation of the `debug!` " +"statements within `rustc` itself, you need a debug version of `rustc`; you " +"can get one by invoking `configure` with the `--enable-debug` option." +msgstr "" + +#. type: Plain text +#: doc/complement-usage-faq.md:24 +msgid "" +"# What does it mean when a program exits with `leaked memory in rust main " +"loop (2 objects)' failed, rt/memory_region.cpp:99 2 objects`?" +msgstr "" + +#. type: Plain text +#: doc/complement-usage-faq.md:26 +msgid "" +"This message indicates a memory leak, and is mostly likely to happen on " +"rarely exercised failure paths. Note that failure unwinding is not yet " +"implemented on windows so this is expected. If you see this on Linux or Mac " +"it's a compiler bug; please report it." +msgstr "" + +#. type: Plain text +#: doc/complement-usage-faq.md:28 +msgid "" +"# Why do gdb backtraces end with the error 'previous frame inner to this " +"frame (corrupt stack?)'?" +msgstr "" + +#. type: Plain text +#: doc/complement-usage-faq.md:30 +#, no-wrap +msgid "**Short answer** your gdb is too old to understand our hip new stacks. Upgrade to a newer version (7.3.1 is known to work).\n" +msgstr "" + +#. type: Plain text +#: doc/complement-usage-faq.md:32 +#, no-wrap +msgid "**Long answer** Rust uses 'spaghetti stacks' (a linked list of stacks) to allow tasks to start very small but recurse arbitrarily deep when necessary. As a result, new frames don't always decrease the stack pointer like gdb expects but instead may jump around the heap to different stack segments. Newer versions of gdb recognize that the special function called __morestack may change the stack pointer to a different stack.\n" +msgstr "" + +#. type: Plain text +#: doc/complement-usage-faq.md:34 +msgid "" +"# Why did my build create a bunch of zero-length files in my lib directory?" +msgstr "" + +#. type: Plain text +#: doc/complement-usage-faq.md:35 +msgid "" +"This is a normal part of the Rust build process. The build system uses these " +"zero-length files for dependency tracking, as the actual names of the Rust " +"libraries contain hashes that can't be guessed easily by the Makefiles." +msgstr "" diff --git a/doc/po/ja/guide-conditions.md.po b/doc/po/ja/guide-conditions.md.po new file mode 100644 index 0000000000000..82890a9690e10 --- /dev/null +++ b/doc/po/ja/guide-conditions.md.po @@ -0,0 +1,1256 @@ +# Japanese translations for Rust package +# Copyright (C) 2014 The Rust Project Developers +# This file is distributed under the same license as the Rust package. +# Automatically generated, 2014. +# +msgid "" +msgstr "" +"Project-Id-Version: Rust 0.9\n" +"POT-Creation-Date: 2014-01-10 12:20+0900\n" +"PO-Revision-Date: 2014-01-10 12:20+0900\n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: ja\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=1; plural=0;\n" + +#. type: Plain text +#: doc/guide-conditions.md:2 +msgid "% The Rust Condition and Error-handling Guide" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:4 doc/guide-ffi.md:4 doc/guide-lifetimes.md:4 +#: doc/guide-macros.md:4 doc/guide-rustpkg.md:4 doc/guide-tasks.md:4 +#: doc/rust.md:4 doc/rustpkg.md:4 doc/tutorial.md:4 +msgid "# Introduction" +msgstr "# イントロダクション" + +#. type: Plain text +#: doc/guide-conditions.md:9 +msgid "" +"Rust does not provide exception handling[^why-no-exceptions] in the form " +"most commonly seen in other programming languages such as C++ or Java. " +"Instead, it provides four mechanisms that work together to handle errors or " +"other rare events. The four mechanisms are:" +msgstr "" + +#. type: Bullet: ' - ' +#: doc/guide-conditions.md:14 +msgid "Options" +msgstr "" + +#. type: Bullet: ' - ' +#: doc/guide-conditions.md:14 +msgid "Results" +msgstr "" + +#. type: Bullet: ' - ' +#: doc/guide-conditions.md:14 +msgid "Failure" +msgstr "" + +#. type: Bullet: ' - ' +#: doc/guide-conditions.md:14 +#, fuzzy +#| msgid "## Conditionals" +msgid "Conditions" +msgstr "## 条件式" + +#. type: Plain text +#: doc/guide-conditions.md:17 +msgid "" +"This guide will lead you through use of these mechanisms in order to " +"understand the trade-offs of each and relationships between them." +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:19 +msgid "# Example program" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:25 +msgid "" +"This guide will be based around an example program that attempts to read " +"lines from a file consisting of pairs of numbers, and then print them back " +"out with slightly different formatting. The input to the program might look " +"like this:" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:33 +msgid "~~~~ {.notrust} $ cat numbers.txt 1 2 34 56 789 123 45 67 ~~~~" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:35 +msgid "For which the intended output looks like this:" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:43 +msgid "" +"~~~~ {.notrust} $ ./example numbers.txt 0001, 0002 0034, 0056 0789, 0123 " +"0045, 0067 ~~~~" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:45 +msgid "An example program that does this task reads like this:" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:64 doc/guide-conditions.md:368 +#: doc/guide-conditions.md:438 doc/guide-conditions.md:514 +#: doc/guide-conditions.md:600 doc/guide-conditions.md:725 +#, no-wrap +msgid "" +"~~~~\n" +"# #[allow(unused_imports)];\n" +"# extern mod extra;\n" +"use std::io::buffered::BufferedReader;\n" +"use std::io::File;\n" +"# mod BufferedReader {\n" +"# use std::io::File;\n" +"# use std::io::mem::MemReader;\n" +"# use std::io::buffered::BufferedReader;\n" +"# static s : &'static [u8] = bytes!(\"1 2\\n\\\n" +"# 34 56\\n\\\n" +"# 789 123\\n\\\n" +"# 45 67\\n\\\n" +"# \");\n" +"# pub fn new(_inner: Option) -> BufferedReader {\n" +"# BufferedReader::new(MemReader::new(s.to_owned()))\n" +"# }\n" +"# }\n" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:71 doc/guide-conditions.md:380 +#, no-wrap +msgid "" +"fn main() {\n" +" let pairs = read_int_pairs();\n" +" for &(a,b) in pairs.iter() {\n" +" println!(\"{:4.4d}, {:4.4d}\", a, b);\n" +" }\n" +"}\n" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:74 +#, no-wrap +msgid "" +"fn read_int_pairs() -> ~[(int,int)] {\n" +" let mut pairs = ~[];\n" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:79 +#, no-wrap +msgid "" +" // Path takes a generic by-value, rather than by reference\n" +"# let _g = std::io::ignore_io_error();\n" +" let path = Path::new(&\"foo.txt\");\n" +" let mut reader = BufferedReader::new(File::open(&path));\n" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:86 +#, no-wrap +msgid "" +" // 1. Iterate over the lines of our file.\n" +" for line in reader.lines() {\n" +" // 2. Split the line into fields (\"words\").\n" +" let fields = line.words().to_owned_vec();\n" +" // 3. Match the vector of fields against a vector pattern.\n" +" match fields {\n" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:91 +#, no-wrap +msgid "" +" // 4. When the line had two fields:\n" +" [a, b] => {\n" +" // 5. Try parsing both fields as ints.\n" +" match (from_str::(a), from_str::(b)) {\n" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:105 +#, no-wrap +msgid "" +" // 6. If parsing succeeded for both, push both.\n" +" (Some(a), Some(b)) => pairs.push((a,b)),\n" +" // 7. Ignore non-int fields.\n" +" _ => ()\n" +" }\n" +" }\n" +" // 8. Ignore lines that don't have 2 fields.\n" +" _ => ()\n" +" }\n" +" }\n" +" pairs\n" +"}\n" +"~~~~\n" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:110 +msgid "" +"This example shows the use of `Option`, along with some other forms of error-" +"handling (and non-handling). We will look at these mechanisms and then " +"modify parts of the example to perform \"better\" error handling." +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:112 +#, fuzzy +#| msgid "# Functions" +msgid "# Options" +msgstr "# 関数" + +#. type: Plain text +#: doc/guide-conditions.md:124 +msgid "" +"The simplest and most lightweight mechanism in Rust for indicating an error " +"is the type `std::option::Option`. This type is a general purpose `enum` " +"for conveying a value of type `T`, represented as `Some(T)` _or_ the " +"sentinel `None`, to indicate the absence of a `T` value. For simple APIs, " +"it may be sufficient to encode errors as `Option`, returning `Some(T)` on " +"success and `None` on error. In the example program, the call to `from_str::" +"` returns `Option` with the understanding that \"all parse errors" +"\" result in `None`. The resulting `Option` values are matched against " +"the pattern `(Some(a), Some(b))` in steps 5 and 6 in the example program, to " +"handle the case in which both fields were parsed successfully." +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:126 +msgid "Using `Option` as in this API has some advantages:" +msgstr "" + +#. type: Bullet: ' - ' +#: doc/guide-conditions.md:131 +msgid "Simple API, users can read it and guess how it works." +msgstr "" + +#. type: Bullet: ' - ' +#: doc/guide-conditions.md:131 +msgid "Very efficient, only an extra `enum` tag on return values." +msgstr "" + +#. type: Bullet: ' - ' +#: doc/guide-conditions.md:131 +msgid "Caller has flexibility in handling or propagating errors." +msgstr "" + +#. type: Bullet: ' - ' +#: doc/guide-conditions.md:131 +msgid "" +"Caller is forced to acknowledge existence of possible-error before using " +"value." +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:133 +msgid "However, it has serious disadvantages too:" +msgstr "" + +#. type: Bullet: ' - ' +#: doc/guide-conditions.md:141 +msgid "" +"Verbose, requires matching results or calling `Option::unwrap` everywhere." +msgstr "" + +#. type: Bullet: ' - ' +#: doc/guide-conditions.md:141 +msgid "" +"Infects caller: if caller doesn't know how to handle the error, must " +"propagate (or force)." +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:141 +#, no-wrap +msgid "" +" - Temptation to do just that: force the `Some(T)` case by blindly calling `unwrap`,\n" +" which hides the error from the API without providing any way to make the program robust against the error.\n" +" - Collapses all errors into one:\n" +" - Caller can't handle different errors differently.\n" +" - Caller can't even report a very precise error message\n" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:146 +msgid "" +"Note that in order to keep the example code reasonably compact, several " +"unwanted cases are silently ignored: lines that do not contain two fields, " +"as well as fields that do not parse as ints. To propagate these cases to " +"the caller using `Option` would require even more verbose code." +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:148 +msgid "# Results" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:158 +msgid "" +"Before getting into _trapping_ the error, we will look at a slight " +"refinement on the `Option` type above. This second mechanism for indicating " +"an error is called a `Result`. The type `std::result::Result` is " +"another simple `enum` type with two forms, `Ok(T)` and `Err(E)`. The " +"`Result` type is not substantially different from the `Option` type in terms " +"of its ergonomics. Its main advantage is that the error constructor " +"`Err(E)` can convey _more detail_ about the error. For example, the " +"`from_str` API could be reformed to return a `Result` carrying an " +"informative description of a parse error, like this:" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:165 +#, no-wrap +msgid "" +"~~~~ {.ignore}\n" +"enum IntParseErr {\n" +" EmptyInput,\n" +" Overflow,\n" +" BadChar(char)\n" +"}\n" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:170 +#, no-wrap +msgid "" +"fn from_str(&str) -> Result {\n" +" // ...\n" +"}\n" +"~~~~\n" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:177 +msgid "" +"This would give the caller more information for both handling and reporting " +"the error, but would otherwise retain the verbosity problems of using " +"`Option`. In particular, it would still be necessary for the caller to " +"return a further `Result` to _its_ caller if it did not want to handle the " +"error. Manually propagating result values this way can be attractive in " +"certain circumstances — for example when processing must halt on the " +"very first error, or backtrack — but as we will see later, many cases " +"have simpler options available." +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:179 +msgid "# Failure" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:184 +msgid "" +"The third and arguably easiest mechanism for handling errors is called " +"\"failure\". In fact it was hinted at earlier by suggesting that one can " +"choose to propagate `Option` or `Result` types _or \"force\" them_. " +"\"Forcing\" them, in this case, means calling a method like `Option::" +"unwrap`, which contains the following code:" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:193 +#, no-wrap +msgid "" +"~~~~ {.ignore}\n" +"pub fn unwrap(self) -> T {\n" +" match self {\n" +" Some(x) => return x,\n" +" None => fail!(\"option::unwrap `None`\")\n" +" }\n" +"}\n" +"~~~~\n" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:195 +msgid "" +"That is, it returns `T` when `self` is `Some(T)`, and _fails_ when `self` is " +"`None`." +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:205 +msgid "" +"Every Rust task can _fail_, either indirectly due to a kill signal or other " +"asynchronous event, or directly by failing an `assert!` or calling the `fail!" +"` macro. Failure is an _unrecoverable event_ at the task level: it causes " +"the task to halt normal execution and unwind its control stack, freeing all " +"task-local resources (the local heap as well as any task-owned values from " +"the global heap) and running destructors (the `drop` method of the `Drop` " +"trait) as frames are unwound and heap values destroyed. A failing task is " +"not permitted to \"catch\" the unwinding during failure and recover, it is " +"only allowed to clean up and exit." +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:207 +msgid "Failure has advantages:" +msgstr "" + +#. type: Bullet: ' - ' +#: doc/guide-conditions.md:213 +msgid "" +"Simple and non-verbose. Suitable for programs that can't reasonably continue " +"past an error anyways." +msgstr "" + +#. type: Bullet: ' - ' +#: doc/guide-conditions.md:213 +msgid "" +"_All_ errors (except memory-safety errors) can be uniformly trapped in a " +"supervisory task outside the failing task. For a large program to be robust " +"against a variety of errors, often some form of task-level partitioning to " +"contain pervasive errors (arithmetic overflow, division by zero, logic bugs) " +"is necessary anyways." +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:215 +msgid "As well as obvious disadvantages:" +msgstr "" + +#. type: Bullet: ' - ' +#: doc/guide-conditions.md:217 +msgid "A blunt instrument, terminates the containing task entirely." +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:221 +msgid "" +"Recall that in the first two approaches to error handling, the example " +"program was only handling success cases, and ignoring error cases. That is, " +"if the input is changed to contain a malformed line:" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:230 +msgid "~~~~ {.notrust} $ cat bad.txt 1 2 34 56 ostrich 789 123 45 67 ~~~~" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:232 +msgid "Then the program would give the same output as if there was no error:" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:240 doc/guide-conditions.md:574 +msgid "" +"~~~~ {.notrust} $ ./example bad.txt 0001, 0002 0034, 0056 0789, 0123 0045, " +"0067 ~~~~" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:244 +msgid "" +"If the example is rewritten to use failure, these error cases can be " +"trapped. In this rewriting, failures are trapped by placing the I/O logic " +"in a sub-task, and trapping its exit status using `task::try`:" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:264 +#, no-wrap +msgid "" +"~~~~\n" +"# #[allow(unused_imports)];\n" +"# extern mod extra;\n" +"use std::io::buffered::BufferedReader;\n" +"use std::io::File;\n" +"use std::task;\n" +"# mod BufferedReader {\n" +"# use std::io::File;\n" +"# use std::io::mem::MemReader;\n" +"# use std::io::buffered::BufferedReader;\n" +"# static s : &'static [u8] = bytes!(\"1 2\\n\\\n" +"# 34 56\\n\\\n" +"# 789 123\\n\\\n" +"# 45 67\\n\\\n" +"# \");\n" +"# pub fn new(_inner: Option) -> BufferedReader {\n" +"# BufferedReader::new(MemReader::new(s.to_owned()))\n" +"# }\n" +"# }\n" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:266 +msgid "fn main() {" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:269 +#, no-wrap +msgid "" +" // Isolate failure within a subtask.\n" +" let result = do task::try {\n" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:275 doc/guide-conditions.md:529 +#: doc/guide-conditions.md:624 +#, no-wrap +msgid "" +" // The protected logic.\n" +" let pairs = read_int_pairs();\n" +" for &(a,b) in pairs.iter() {\n" +" println!(\"{:4.4d}, {:4.4d}\", a, b);\n" +" }\n" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:281 +#, no-wrap +msgid "" +" };\n" +" if result.is_err() {\n" +" println(\"parsing failed\");\n" +" }\n" +"}\n" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:286 doc/guide-conditions.md:385 +#: doc/guide-conditions.md:460 doc/guide-conditions.md:537 +#: doc/guide-conditions.md:632 doc/guide-conditions.md:771 +#, no-wrap +msgid "" +"fn read_int_pairs() -> ~[(int,int)] {\n" +" let mut pairs = ~[];\n" +"# let _g = std::io::ignore_io_error();\n" +" let path = Path::new(&\"foo.txt\");\n" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:292 doc/guide-conditions.md:543 +#: doc/guide-conditions.md:638 +#, no-wrap +msgid "" +" let mut reader = BufferedReader::new(File::open(&path));\n" +" for line in reader.lines() {\n" +" match line.words().to_owned_vec() {\n" +" [a, b] => pairs.push((from_str::(a).unwrap(),\n" +" from_str::(b).unwrap())),\n" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:300 +#, no-wrap +msgid "" +" // Explicitly fail on malformed lines.\n" +" _ => fail!()\n" +" }\n" +" }\n" +" pairs\n" +"}\n" +"~~~~\n" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:302 +msgid "" +"With these changes in place, running the program on malformed input gives a " +"different answer:" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:308 +msgid "" +"~~~~ {.notrust} $ ./example bad.txt rust: task failed at 'explicit " +"failure', ./example.rs:44 parsing failed ~~~~" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:316 +msgid "" +"Note that while failure unwinds the sub-task performing I/O in " +"`read_int_pairs`, control returns to `main` and can easily continue " +"uninterrupted. In this case, control simply prints out `parsing failed` and " +"then exits `main` (successfully). Failure of a (sub-)task is analogous to " +"calling `exit(1)` or `abort()` in a unix C program: all the state of a sub-" +"task is cleanly discarded on exit, and a supervisor task can take " +"appropriate action without worrying about its own state having been " +"corrupted." +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:318 +#, fuzzy +#| msgid "## Conditionals" +msgid "# Conditions" +msgstr "## 条件式" + +#. type: Plain text +#: doc/guide-conditions.md:324 +msgid "" +"The final mechanism for handling errors is called a \"condition\". " +"Conditions are less blunt than failure, and less cumbersome than the " +"`Option` or `Result` types; indeed they are designed to strike just the " +"right balance between the two. Conditions require some care to use " +"effectively, but give maximum flexibility with minimum verbosity. While " +"conditions use exception-like terminology (\"trap\", \"raise\") they are " +"significantly different:" +msgstr "" + +#. type: Bullet: ' - ' +#: doc/guide-conditions.md:328 +msgid "" +"Like exceptions and failure, conditions separate the site at which the error " +"is raised from the site where it is trapped." +msgstr "" + +#. type: Bullet: ' - ' +#: doc/guide-conditions.md:328 +msgid "" +"Unlike exceptions and unlike failure, when a condition is raised and " +"trapped, _no unwinding occurs_." +msgstr "" + +#. type: Bullet: ' - ' +#: doc/guide-conditions.md:328 +msgid "" +"A successfully trapped condition causes execution to continue _at the site " +"of the error_, as though no error occurred." +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:332 +msgid "" +"Conditions are declared with the `condition!` macro. Each condition has a " +"name, an input type and an output type, much like a function. In fact, " +"conditions are implemented as dynamically-scoped functions held in task " +"local storage." +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:338 +msgid "" +"The `condition!` macro declares a module with the name of the condition; the " +"module contains a single static value called `cond`, of type `std::" +"condition::Condition`. The `cond` value within the module is the rendezvous " +"point between the site of error and the site that handles the error. It has " +"two methods of interest: `raise` and `trap`." +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:346 +msgid "" +"The `raise` method maps a value of the condition's input type to its output " +"type. The input type should therefore convey all relevant information to " +"the condition handler. The output type should convey all relevant " +"information _for continuing execution at the site of error_. When the error " +"site raises a condition handler, the `Condition::raise` method searches for " +"the innermost installed task-local condition _handler_, and if any such " +"handler is found, calls it with the provided input value. If no handler is " +"found, `Condition::raise` will fail the task with an appropriate error " +"message." +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:349 +msgid "" +"Rewriting the example to use a condition in place of ignoring malformed " +"lines makes it slightly longer, but similarly clear as the version that used " +"`fail!` in the logic where the error occurs:" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:373 +#, no-wrap +msgid "" +"// Introduce a new condition.\n" +"condition! {\n" +" pub malformed_line : ~str -> (int,int);\n" +"}\n" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:399 +#, no-wrap +msgid "" +" let mut reader = BufferedReader::new(File::open(&path));\n" +" for line in reader.lines() {\n" +" match line.words().to_owned_vec() {\n" +" [a, b] => pairs.push((from_str::(a).unwrap(),\n" +" from_str::(b).unwrap())),\n" +" // On malformed lines, call the condition handler and\n" +" // push whatever the condition handler returns.\n" +" _ => pairs.push(malformed_line::cond.raise(line.clone()))\n" +" }\n" +" }\n" +" pairs\n" +"}\n" +"~~~~\n" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:402 +msgid "" +"When this is run on malformed input, it still fails, but with a slightly " +"different failure message than before:" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:407 +msgid "" +"~~~~ {.notrust} $ ./example bad.txt rust: task failed at 'Unhandled " +"condition: malformed_line: ~\"ostrich\"', .../libstd/condition.rs:43 ~~~~" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:413 +msgid "" +"While this superficially resembles the trapped `fail!` call before, it is " +"only because the example did not install a handler for the condition. The " +"different failure message is indicating, among other things, that the " +"condition-handling system is being invoked and failing only due to the " +"absence of a _handler_ that traps the condition." +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:415 +msgid "# Trapping a condition" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:419 +msgid "" +"To trap a condition, use `Condition::trap` in some caller of the site that " +"calls `Condition::raise`. For example, this version of the program traps " +"the `malformed_line` condition and replaces bad input lines with the pair " +"`(-1,-1)`:" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:442 +#, no-wrap +msgid "" +"condition! {\n" +" pub malformed_line : ~str -> (int,int);\n" +"}\n" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:446 +#, no-wrap +msgid "" +"fn main() {\n" +" // Trap the condition:\n" +" malformed_line::cond.trap(|_| (-1,-1)).inside(|| {\n" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:452 +#, no-wrap +msgid "" +" // The protected logic.\n" +" let pairs = read_int_pairs();\n" +" for &(a,b) in pairs.iter() {\n" +" println!(\"{:4.4d}, {:4.4d}\", a, b);\n" +" }\n" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:455 doc/guide-conditions.md:532 +#: doc/guide-conditions.md:627 +#, no-wrap +msgid "" +" })\n" +"}\n" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:472 +#, no-wrap +msgid "" +" let mut reader = BufferedReader::new(File::open(&path));\n" +" for line in reader.lines() {\n" +" match line.words().to_owned_vec() {\n" +" [a, b] => pairs.push((from_str::(a).unwrap(),\n" +" from_str::(b).unwrap())),\n" +" _ => pairs.push(malformed_line::cond.raise(line.clone()))\n" +" }\n" +" }\n" +" pairs\n" +"}\n" +"~~~~\n" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:477 +msgid "" +"Note that the remainder of the program is _unchanged_ with this trap in " +"place; only the caller that installs the trap changed. Yet when the " +"condition-trapping variant runs on the malformed input, it continues " +"execution past the malformed line, substituting the handler's return value." +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:486 +msgid "" +"~~~~ {.notrust} $ ./example bad.txt 0001, 0002 0034, 0056 -0001, -0001 0789, " +"0123 0045, 0067 ~~~~" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:488 +msgid "# Refining a condition" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:495 +msgid "" +"As you work with a condition, you may find that the original set of options " +"you present for recovery is insufficient. This is no different than any " +"other issue of API design: a condition handler is an API for recovering from " +"the condition, and sometimes APIs need to be enriched. In the example " +"program, the first form of the `malformed_line` API implicitly assumes that " +"recovery involves a substitute value. This assumption may not be correct; " +"some callers may wish to skip malformed lines, for example. Changing the " +"condition's return type from `(int,int)` to `Option<(int,int)>` will suffice " +"to support this type of recovery:" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:519 +#, no-wrap +msgid "" +"// Modify the condition signature to return an Option.\n" +"condition! {\n" +" pub malformed_line : ~str -> Option<(int,int)>;\n" +"}\n" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:523 +#, no-wrap +msgid "" +"fn main() {\n" +" // Trap the condition and return `None`\n" +" malformed_line::cond.trap(|_| None).inside(|| {\n" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:558 +#, no-wrap +msgid "" +" // On malformed lines, call the condition handler and\n" +" // either ignore the line (if the handler returns `None`)\n" +" // or push any `Some(pair)` value returned instead.\n" +" _ => {\n" +" match malformed_line::cond.raise(line.clone()) {\n" +" Some(pair) => pairs.push(pair),\n" +" None => ()\n" +" }\n" +" }\n" +" }\n" +" }\n" +" pairs\n" +"}\n" +"~~~~\n" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:566 +msgid "" +"Again, note that the remainder of the program is _unchanged_, in particular " +"the signature of `read_int_pairs` is unchanged, even though the innermost " +"part of its reading-loop has a new way of handling a malformed line. When " +"the example is run with the `None` trap in place, the line is ignored as it " +"was in the first example, but the choice of whether to ignore or use a " +"substitute value has been moved to some caller, possibly a distant caller." +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:576 +msgid "# Further refining a condition" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:581 +msgid "" +"Like with any API, the process of refining argument and return types of a " +"condition will continue, until all relevant combinations encountered in " +"practice are encoded. In the example, suppose a third possible recovery " +"form arose: reusing the previous value read. This can be encoded in the " +"handler API by introducing a helper type: `enum MalformedLineFix`." +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:607 +#, no-wrap +msgid "" +"// Introduce a new enum to convey condition-handling strategy to error site.\n" +"pub enum MalformedLineFix {\n" +" UsePair(int,int),\n" +" IgnoreLine,\n" +" UsePreviousLine\n" +"}\n" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:614 +#, no-wrap +msgid "" +"// Modify the condition signature to return the new enum.\n" +"// Note: a condition introduces a new module, so the enum must be\n" +"// named with the `super::` prefix to access it.\n" +"condition! {\n" +" pub malformed_line : ~str -> super::MalformedLineFix;\n" +"}\n" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:618 +#, no-wrap +msgid "" +"fn main() {\n" +" // Trap the condition and return `UsePreviousLine`\n" +" malformed_line::cond.trap(|_| UsePreviousLine).inside(|| {\n" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:656 +#, no-wrap +msgid "" +" // On malformed lines, call the condition handler and\n" +" // take action appropriate to the enum value returned.\n" +" _ => {\n" +" match malformed_line::cond.raise(line.clone()) {\n" +" UsePair(a,b) => pairs.push((a,b)),\n" +" IgnoreLine => (),\n" +" UsePreviousLine => {\n" +" let prev = pairs[pairs.len() - 1];\n" +" pairs.push(prev)\n" +" }\n" +" }\n" +" }\n" +" }\n" +" }\n" +" pairs\n" +"}\n" +"~~~~\n" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:659 +msgid "" +"Running the example with `UsePreviousLine` as the fix code returned from the " +"handler gives the expected result:" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:668 +msgid "" +"~~~~ {.notrust} $ ./example bad.txt 0001, 0002 0034, 0056 0034, 0056 0789, " +"0123 0045, 0067 ~~~~" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:674 +msgid "" +"At this point the example has a rich variety of recovery options, none of " +"which is visible to casual users of the `read_int_pairs` function. This is " +"intentional: part of the purpose of using a condition is to free " +"intermediate callers from the burden of having to write repetitive error-" +"propagation logic, and/or having to change function call and return types as " +"error-handling strategies are refined." +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:676 +msgid "# Multiple conditions, intermediate callers" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:682 +msgid "" +"So far the function trapping the condition and the function raising it have " +"been immediately adjacent in the call stack. That is, the caller traps and " +"its immediate callee raises. In most programs, the function that traps may " +"be separated by very many function calls from the function that raises. " +"Again, this is part of the point of using conditions: to support that " +"separation without having to thread multiple error values and recovery " +"strategies all the way through the program's main logic." +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:686 +msgid "" +"Careful readers will notice that there is a remaining failure mode in the " +"example program: the call to `.unwrap()` when parsing each integer. For " +"example, when presented with a file that has the correct number of fields on " +"a line, but a non-numeric value in one of them, such as this:" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:695 +msgid "~~~~ {.notrust} $ cat bad.txt 1 2 34 56 7 marmot 789 123 45 67 ~~~~" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:698 +msgid "Then the program fails once more:" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:703 +msgid "" +"~~~~ {.notrust} $ ./example bad.txt task failed at 'called " +"`Option::unwrap()` on a `None` value', .../libstd/option.rs:314 ~~~~" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:706 +msgid "" +"To make the program robust — or at least flexible — in the face " +"of this potential failure, a second condition and a helper function will " +"suffice:" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:731 +#, no-wrap +msgid "" +"pub enum MalformedLineFix {\n" +" UsePair(int,int),\n" +" IgnoreLine,\n" +" UsePreviousLine\n" +"}\n" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:735 +#, no-wrap +msgid "" +"condition! {\n" +" pub malformed_line : ~str -> ::MalformedLineFix;\n" +"}\n" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:740 +#, no-wrap +msgid "" +"// Introduce a second condition.\n" +"condition! {\n" +" pub malformed_int : ~str -> int;\n" +"}\n" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:744 +#, no-wrap +msgid "" +"fn main() {\n" +" // Trap the `malformed_int` condition and return -1\n" +" malformed_int::cond.trap(|_| -1).inside(|| {\n" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:747 +#, no-wrap +msgid "" +" // Trap the `malformed_line` condition and return `UsePreviousLine`\n" +" malformed_line::cond.trap(|_| UsePreviousLine).inside(|| {\n" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:753 +#, no-wrap +msgid "" +" // The protected logic.\n" +" let pairs = read_int_pairs();\n" +" for &(a,b) in pairs.iter() {\n" +" println!(\"{:4.4d}, {:4.4d}\", a, b);\n" +" }\n" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:757 +#, no-wrap +msgid "" +" })\n" +" })\n" +"}\n" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:766 +#, no-wrap +msgid "" +"// Parse an int; if parsing fails, call the condition handler and\n" +"// return whatever it returns.\n" +"fn parse_int(x: &str) -> int {\n" +" match from_str::(x) {\n" +" Some(v) => v,\n" +" None => malformed_int::cond.raise(x.to_owned())\n" +" }\n" +"}\n" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:778 +#, no-wrap +msgid "" +" let mut reader = BufferedReader::new(File::open(&path));\n" +" for line in reader.lines() {\n" +" match line.words().to_owned_vec() {\n" +" // Delegate parsing ints to helper function that will\n" +" // handle parse errors by calling `malformed_int`.\n" +" [a, b] => pairs.push((parse_int(a), parse_int(b))),\n" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:794 +#, no-wrap +msgid "" +" _ => {\n" +" match malformed_line::cond.raise(line.clone()) {\n" +" UsePair(a,b) => pairs.push((a,b)),\n" +" IgnoreLine => (),\n" +" UsePreviousLine => {\n" +" let prev = pairs[pairs.len() - 1];\n" +" pairs.push(prev)\n" +" }\n" +" }\n" +" }\n" +" }\n" +" }\n" +" pairs\n" +"}\n" +"~~~~\n" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:798 +msgid "" +"Again, note that `read_int_pairs` has not changed signature, nor has any of " +"the machinery for trapping or raising `malformed_line`, but now the program " +"can handle the \"right number of fields, non-integral field\" form of bad " +"input:" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:807 +msgid "" +"~~~~ {.notrust} $ ./example bad.txt 0001, 0002 0034, 0056 0007, -0001 0789, " +"0123 0045, 0067 ~~~~" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:809 +msgid "" +"There are three other things to note in this variant of the example program:" +msgstr "" + +#. type: Bullet: ' - ' +#: doc/guide-conditions.md:812 +msgid "" +"It traps multiple conditions simultaneously, nesting the protected logic of " +"one `trap` call inside the other." +msgstr "" + +#. type: Bullet: ' - ' +#: doc/guide-conditions.md:817 +msgid "" +"There is a function in between the `trap` site and `raise` site for the " +"`malformed_int` condition. There could be any number of calls between them: " +"so long as the `raise` occurs within a callee (of any depth) of the logic " +"protected by the `trap` call, it will invoke the handler." +msgstr "" + +#. type: Bullet: ' - ' +#: doc/guide-conditions.md:822 +msgid "" +"This variant insulates callers from a design choice in the library: the " +"`from_str` function was designed to return an `Option`, but this " +"program insulates callers from that choice, routing all `None` values that " +"arise from parsing integers in this file into the condition." +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:825 +msgid "# When to use which technique" +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:828 +msgid "" +"This guide explored several techniques for handling errors. Each is " +"appropriate to different circumstances:" +msgstr "" + +#. type: Bullet: ' - ' +#: doc/guide-conditions.md:834 +msgid "" +"If an error may be extremely frequent, expected, and very likely dealt with " +"by an immediate caller, then returning an `Option` or `Result` type is best. " +"These types force the caller to handle the error, and incur the lowest speed " +"overhead, usually only returning one extra word to tag the return value. " +"Between `Option` and `Result`: use an `Option` when there is only one kind " +"of error, otherwise make an `enum FooErr` to represent the possible error " +"codes and use `Result`." +msgstr "" + +#. type: Bullet: ' - ' +#: doc/guide-conditions.md:839 +msgid "" +"If an error can reasonably be handled at the site it occurs by one of a few " +"strategies — possibly including failure — and it is not clear " +"which strategy a caller would want to use, a condition is best. For many " +"errors, the only reasonable \"non-stop\" recovery strategies are to retry " +"some number of times, create or substitute an empty or sentinel value, " +"ignore the error, or fail." +msgstr "" + +#. type: Bullet: ' - ' +#: doc/guide-conditions.md:843 +msgid "" +"If an error cannot reasonably be handled at the site it occurs, and the only " +"reasonable response is to abandon a large set of operations in progress, " +"then directly failing is best." +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:847 +msgid "" +"Note that an unhandled condition will cause failure (along with a more-" +"informative-than-usual message), so if there is any possibility that a " +"caller might wish to \"ignore and keep going\", it is usually harmless to " +"use a condition in place of a direct call to `fail!()`." +msgstr "" + +#. type: Plain text +#: doc/guide-conditions.md:858 +msgid "" +"[^why-no-exceptions]: Exceptions in languages like C++ and Java permit " +"unwinding, like Rust's failure system, but with the option to halt unwinding " +"partway through the process and continue execution. This behavior " +"unfortunately means that the _heap_ may be left in an inconsistent but " +"accessible state, if an exception is thrown part way through the process of " +"initializing or modifying memory. To compensate for this risk, correct C++ " +"and Java code must program in an extremely elaborate and difficult " +"\"exception-safe\" style — effectively transactional style against " +"heap structures — or else risk introducing silent and very difficult-" +"to-debug errors due to control resuming in a corrupted heap after a caught " +"exception. These errors are frequently memory-safety errors, which Rust " +"strives to eliminate, and so Rust unwinding is unrecoverable within a single " +"task: once unwinding starts, the entire local heap of a task is destroyed " +"and the task is terminated." +msgstr "" diff --git a/doc/po/ja/tutorial-container.md.po b/doc/po/ja/guide-container.md.po similarity index 57% rename from doc/po/ja/tutorial-container.md.po rename to doc/po/ja/guide-container.md.po index 02513417844f7..503c1648f4f36 100644 --- a/doc/po/ja/tutorial-container.md.po +++ b/doc/po/ja/guide-container.md.po @@ -1,13 +1,13 @@ # Japanese translations for Rust package -# Copyright (C) 2013 The Rust Project Developers +# Copyright (C) 2014 The Rust Project Developers # This file is distributed under the same license as the Rust package. -# Automatically generated, 2013. +# Automatically generated, 2014. # msgid "" msgstr "" -"Project-Id-Version: Rust 0.8\n" -"POT-Creation-Date: 2013-08-05 19:40+0900\n" -"PO-Revision-Date: 2013-07-28 20:32+0900\n" +"Project-Id-Version: Rust 0.9\n" +"POT-Creation-Date: 2014-01-10 12:20+0900\n" +"PO-Revision-Date: 2014-01-10 12:20+0900\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" "Language: ja\n" @@ -17,48 +17,52 @@ msgstr "" "Plural-Forms: nplurals=1; plural=0;\n" #. type: Plain text -#: doc/tutorial-container.md:2 -msgid "% Containers and iterators" -msgstr "" +#: doc/complement-cheatsheet.md:88 doc/guide-container.md:4 +#, fuzzy +#| msgid "## Conventions" +msgid "# Containers" +msgstr "## 本書の表記について" #. type: Plain text -#: doc/tutorial-container.md:4 -msgid "# Containers" +#: doc/guide-container.md:2 +msgid "% The Rust Containers and Iterators Guide" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:6 +#: doc/guide-container.md:6 msgid "The container traits are defined in the `std::container` module." msgstr "" #. type: Plain text -#: doc/tutorial-container.md:8 -msgid "## Unique and managed vectors" +#: doc/guide-container.md:8 +msgid "## Unique vectors" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:12 +#: doc/guide-container.md:12 msgid "" -"Vectors have `O(1)` indexing and removal from the end, along with `O(1)` " -"amortized insertion. Vectors are the most common container in Rust, and are " -"flexible enough to fit many use cases." +"Vectors have `O(1)` indexing, push (to the end) and pop (from the end). " +"Vectors are the most common container in Rust, and are flexible enough to " +"fit many use cases." msgstr "" #. type: Plain text -#: doc/tutorial-container.md:16 +#: doc/guide-container.md:16 msgid "" "Vectors can also be sorted and used as efficient lookup tables with the " -"`std::vec::bsearch` function, if all the elements are inserted at one time " -"and deletions are unnecessary." +"`bsearch()` method, if all the elements are inserted at one time and " +"deletions are unnecessary." msgstr "" #. type: Plain text -#: doc/tutorial-container.md:18 +#: doc/guide-container.md:18 +#, fuzzy +#| msgid "## Managed closures" msgid "## Maps and sets" -msgstr "" +msgstr "## マネージドクロージャ" #. type: Plain text -#: doc/tutorial-container.md:22 +#: doc/guide-container.md:22 msgid "" "Maps are collections of unique keys with corresponding values, and sets are " "just unique keys without a corresponding value. The `Map` and `Set` traits " @@ -66,33 +70,33 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:24 +#: doc/guide-container.md:24 msgid "The standard library provides three owned map/set types:" msgstr "" #. type: Bullet: '* ' -#: doc/tutorial-container.md:30 +#: doc/guide-container.md:30 msgid "" "`std::hashmap::HashMap` and `std::hashmap::HashSet`, requiring the keys to " "implement `Eq` and `Hash`" msgstr "" #. type: Bullet: '* ' -#: doc/tutorial-container.md:30 +#: doc/guide-container.md:30 msgid "" "`std::trie::TrieMap` and `std::trie::TrieSet`, requiring the keys to be " "`uint`" msgstr "" #. type: Bullet: '* ' -#: doc/tutorial-container.md:30 +#: doc/guide-container.md:30 msgid "" "`extra::treemap::TreeMap` and `extra::treemap::TreeSet`, requiring the keys " "to implement `TotalOrd`" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:34 +#: doc/guide-container.md:34 msgid "" "These maps do not use managed pointers so they can be sent between tasks as " "long as the key and value types are sendable. Neither the key or value type " @@ -100,14 +104,14 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:37 +#: doc/guide-container.md:37 msgid "" "The `TrieMap` and `TreeMap` maps are ordered, while `HashMap` uses an " "arbitrary order." msgstr "" #. type: Plain text -#: doc/tutorial-container.md:42 +#: doc/guide-container.md:42 msgid "" "Each `HashMap` instance has a random 128-bit key to use with a keyed hash, " "making the order of a set of keys in a given hash table randomized. Rust " @@ -116,26 +120,35 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:44 +#: doc/guide-container.md:44 msgid "## Double-ended queues" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:49 +#: doc/guide-container.md:50 msgid "" -"The `extra::deque` module implements a double-ended queue with `O(1)` " +"The `extra::ringbuf` module implements a double-ended queue with `O(1)` " "amortized inserts and removals from both ends of the container. It also has " "`O(1)` indexing like a vector. The contained elements are not required to be " -"copyable, and the queue will be sendable if the contained type is sendable." +"copyable, and the queue will be sendable if the contained type is sendable. " +"Its interface `Deque` is defined in `extra::collections`." +msgstr "" + +#. type: Plain text +#: doc/guide-container.md:54 +msgid "" +"The `extra::dlist` module implements a double-ended linked list, also " +"implementing the `Deque` trait, with `O(1)` removals and inserts at either " +"end, and `O(1)` concatenation." msgstr "" #. type: Plain text -#: doc/tutorial-container.md:51 +#: doc/guide-container.md:56 msgid "## Priority queues" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:55 +#: doc/guide-container.md:60 msgid "" "The `extra::priority_queue` module implements a queue ordered by a key. The " "contained elements are not required to be copyable, and the queue will be " @@ -143,7 +156,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:61 +#: doc/guide-container.md:66 msgid "" "Insertions have `O(log n)` time complexity and checking or popping the " "largest element is `O(1)`. Converting a vector to a priority queue can be " @@ -153,30 +166,32 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:63 +#: doc/guide-container.md:68 +#, fuzzy +#| msgid "## Operators" msgid "# Iterators" -msgstr "" +msgstr "## 演算子" #. type: Plain text -#: doc/tutorial-container.md:65 +#: doc/guide-container.md:70 msgid "## Iteration protocol" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:69 +#: doc/guide-container.md:74 msgid "" -"The iteration protocol is defined by the `Iterator` trait in the `std::" -"iterator` module. The minimal implementation of the trait is a `next` " -"method, yielding the next element from an iterator object:" +"The iteration protocol is defined by the `Iterator` trait in the `std::iter` " +"module. The minimal implementation of the trait is a `next` method, yielding " +"the next element from an iterator object:" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:73 +#: doc/guide-container.md:78 msgid "~~~ /// An infinite stream of zeroes struct ZeroStream;" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:80 +#: doc/guide-container.md:85 #, no-wrap msgid "" "impl Iterator for ZeroStream {\n" @@ -188,17 +203,18 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:83 +#: doc/guide-container.md:88 msgid "" "Reaching the end of the iterator is signalled by returning `None` instead of " "`Some(item)`:" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:89 doc/tutorial-container.md:262 +#: doc/guide-container.md:95 doc/guide-container.md:310 #, no-wrap msgid "" "~~~\n" +"# fn main() {}\n" "/// A stream of N zeroes\n" "struct ZeroStream {\n" " priv remaining: uint\n" @@ -206,7 +222,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:95 +#: doc/guide-container.md:101 #, no-wrap msgid "" "impl ZeroStream {\n" @@ -217,7 +233,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:107 doc/tutorial-container.md:284 +#: doc/guide-container.md:113 doc/guide-container.md:332 #, no-wrap msgid "" "impl Iterator for ZeroStream {\n" @@ -234,49 +250,59 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:109 -msgid "## Container iterators" +#: doc/guide-container.md:117 +msgid "" +"In general, you cannot rely on the behavior of the `next()` method after it " +"has returned `None`. Some iterators may return `None` forever. Others may " +"behave differently." msgstr "" #. type: Plain text -#: doc/tutorial-container.md:112 +#: doc/guide-container.md:119 +#, fuzzy +#| msgid "# Control structures" +msgid "## Container iterators" +msgstr "# 制御構造" + +#. type: Plain text +#: doc/guide-container.md:122 msgid "" "Containers implement iteration over the contained elements by returning an " "iterator object. For example, vector slices several iterators available:" msgstr "" #. type: Bullet: '* ' -#: doc/tutorial-container.md:116 +#: doc/guide-container.md:126 msgid "`iter()` and `rev_iter()`, for immutable references to the elements" msgstr "" #. type: Bullet: '* ' -#: doc/tutorial-container.md:116 +#: doc/guide-container.md:126 msgid "" "`mut_iter()` and `mut_rev_iter()`, for mutable references to the elements" msgstr "" #. type: Bullet: '* ' -#: doc/tutorial-container.md:116 -msgid "" -"`consume_iter()` and `consume_rev_iter`, to move the elements out by-value" +#: doc/guide-container.md:126 +msgid "`move_iter()` and `move_rev_iter()`, to move the elements out by-value" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:119 +#: doc/guide-container.md:129 msgid "" "A typical mutable container will implement at least `iter()`, `mut_iter()` " -"and `consume_iter()` along with the reverse variants if it maintains an " -"order." +"and `move_iter()` along with the reverse variants if it maintains an order." msgstr "" #. type: Plain text -#: doc/tutorial-container.md:121 +#: doc/guide-container.md:131 +#, fuzzy +#| msgid "## Freezing" msgid "### Freezing" -msgstr "" +msgstr "## 凍結" #. type: Plain text -#: doc/tutorial-container.md:125 +#: doc/guide-container.md:135 msgid "" "Unlike most other languages with external iterators, Rust has no *iterator " "invalidation*. As long an iterator is still in scope, the compiler will " @@ -284,7 +310,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:130 +#: doc/guide-container.md:140 #, no-wrap msgid "" "~~~\n" @@ -294,7 +320,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:136 +#: doc/guide-container.md:146 #, no-wrap msgid "" " // the vector is frozen for this scope, the compiler will statically\n" @@ -305,72 +331,138 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:139 +#: doc/guide-container.md:149 msgid "" "These semantics are due to most container iterators being implemented with " "`&` and `&mut`." msgstr "" #. type: Plain text -#: doc/tutorial-container.md:141 +#: doc/guide-container.md:151 +#, fuzzy +#| msgid "## Operators" msgid "## Iterator adaptors" -msgstr "" +msgstr "## 演算子" #. type: Plain text -#: doc/tutorial-container.md:145 +#: doc/guide-container.md:155 msgid "" -"The `IteratorUtil` trait implements common algorithms as methods extending " -"every `Iterator` implementation. For example, the `fold` method will " -"accumulate the items yielded by an `Iterator` into a single value:" +"The `Iterator` trait provides many common algorithms as default methods. For " +"example, the `fold` method will accumulate the items yielded by an " +"`Iterator` into a single value:" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:151 +#: doc/guide-container.md:161 msgid "" "~~~ let xs = [1, 9, 2, 3, 14, 12]; let result = xs.iter().fold(0, |" "accumulator, item| accumulator - *item); assert_eq!(result, -41); ~~~" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:153 +#: doc/guide-container.md:163 msgid "" -"Some adaptors return an adaptor object implementing the `Iterator` trait " +"Most adaptors return an adaptor object implementing the `Iterator` trait " "itself:" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:160 +#: doc/guide-container.md:170 msgid "" "~~~ let xs = [1, 9, 2, 3, 14, 12]; let ys = [5, 2, 1, 8]; let sum = xs." -"iter().chain_(ys.iter()).fold(0, |a, b| a + *b); assert_eq!(sum, 57); ~~~" +"iter().chain(ys.iter()).fold(0, |a, b| a + *b); assert_eq!(sum, 57); ~~~" +msgstr "" + +#. type: Plain text +#: doc/guide-container.md:176 +msgid "" +"Some iterator adaptors may return `None` before exhausting the underlying " +"iterator. Additionally, if these iterator adaptors are called again after " +"returning `None`, they may call their underlying iterator again even if the " +"adaptor will continue to return `None` forever. This may not be desired if " +"the underlying iterator has side-effects." +msgstr "" + +#. type: Plain text +#: doc/guide-container.md:180 +msgid "" +"In order to provide a guarantee about behavior once `None` has been " +"returned, an iterator adaptor named `fuse()` is provided. This returns an " +"iterator that will never call its underlying iterator again once `None` has " +"been returned:" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:164 +#: doc/guide-container.md:199 +#, no-wrap msgid "" -"Note that some adaptors like the `chain_` method above use a trailing " -"underscore to work around an issue with method resolve. The underscores will " -"be dropped when they become unnecessary." +"~~~\n" +"let xs = [1,2,3,4,5];\n" +"let mut calls = 0;\n" +"let it = xs.iter().scan((), |_, x| {\n" +" calls += 1;\n" +" if *x < 3 { Some(x) } else { None }});\n" +"// the iterator will only yield 1 and 2 before returning None\n" +"// If we were to call it 5 times, calls would end up as 5, despite only 2 values\n" +"// being yielded (and therefore 3 unique calls being made). The fuse() adaptor\n" +"// can fix this.\n" +"let mut it = it.fuse();\n" +"it.next();\n" +"it.next();\n" +"it.next();\n" +"it.next();\n" +"it.next();\n" +"assert_eq!(calls, 3);\n" +"~~~\n" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:166 +#: doc/guide-container.md:201 +#, fuzzy +#| msgid "## Loops" msgid "## For loops" +msgstr "## ループ" + +#. type: Plain text +#: doc/guide-container.md:203 +msgid "" +"The function `range` (or `range_inclusive`) allows to simply iterate through " +"a given range:" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:168 +#: doc/guide-container.md:208 +#, no-wrap +msgid "" +"~~~\n" +"for i in range(0, 5) {\n" +" print!(\"{} \", i) // prints \"0 1 2 3 4\"\n" +"}\n" +msgstr "" + +#. type: Plain text +#: doc/guide-container.md:213 +#, no-wrap +msgid "" +"for i in std::iter::range_inclusive(0, 5) { // needs explicit import\n" +" print!(\"{} \", i) // prints \"0 1 2 3 4 5\"\n" +"}\n" +"~~~\n" +msgstr "" + +#. type: Plain text +#: doc/guide-container.md:215 msgid "" "The `for` keyword can be used as sugar for iterating through any iterator:" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:171 -msgid "~~~ let xs = [2, 3, 5, 7, 11, 13, 17];" +#: doc/guide-container.md:218 +msgid "~~~ let xs = [2u, 3, 5, 7, 11, 13, 17];" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:176 +#: doc/guide-container.md:223 #, no-wrap msgid "" "// print out all the elements in the vector\n" @@ -380,7 +472,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:182 +#: doc/guide-container.md:229 #, no-wrap msgid "" "// print out all but the first 3 elements in the vector\n" @@ -391,37 +483,37 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:185 +#: doc/guide-container.md:232 msgid "" "For loops are *often* used with a temporary iterator object, as above. They " "can also advance the state of an iterator in a mutable location:" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:189 +#: doc/guide-container.md:236 msgid "" "~~~ let xs = [1, 2, 3, 4, 5]; let ys = [\"foo\", \"bar\", \"baz\", \"foobar" "\"];" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:192 +#: doc/guide-container.md:239 msgid "" "// create an iterator yielding tuples of elements from both vectors let mut " "it = xs.iter().zip(ys.iter());" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:196 +#: doc/guide-container.md:243 #, no-wrap msgid "" "// print out the pairs of elements up to (&3, &\"baz\")\n" "for (x, y) in it {\n" -" printfln!(\"%d %s\", *x, *y);\n" +" println!(\"{} {}\", *x, *y);\n" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:201 +#: doc/guide-container.md:248 #, no-wrap msgid "" " if *x == 3 {\n" @@ -431,45 +523,46 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:204 +#: doc/guide-container.md:251 msgid "" -"// yield and print the last pair from the iterator printfln!(\"last: %?\", " +"// yield and print the last pair from the iterator println!(\"last: {:?}\", " "it.next());" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:208 +#: doc/guide-container.md:255 msgid "// the iterator is now fully consumed assert!(it.next().is_none()); ~~~" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:210 +#: doc/guide-container.md:257 +#, fuzzy +#| msgid "## Conventions" msgid "## Conversion" -msgstr "" +msgstr "## 本書の表記について" #. type: Plain text -#: doc/tutorial-container.md:212 +#: doc/guide-container.md:259 msgid "" "Iterators offer generic conversion to containers with the `collect` adaptor:" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:218 +#: doc/guide-container.md:265 msgid "" -"~~~ let xs = [0, 1, 1, 2, 3, 5, 8]; let ys = xs.rev_iter().skip(1)." -"transform(|&x| x * 2).collect::<~[int]>(); assert_eq!(ys, ~[10, 6, 4, 2, 2, " -"0]); ~~~" +"~~~ let xs = [0, 1, 1, 2, 3, 5, 8]; let ys = xs.rev_iter().skip(1).map(|&x| " +"x * 2).collect::<~[int]>(); assert_eq!(ys, ~[10, 6, 4, 2, 2, 0]); ~~~" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:221 +#: doc/guide-container.md:268 msgid "" "The method requires a type hint for the container type, if the surrounding " "code does not provide sufficient information." msgstr "" #. type: Plain text -#: doc/tutorial-container.md:225 +#: doc/guide-container.md:272 msgid "" "Containers can provide conversion from iterators through `collect` by " "implementing the `FromIterator` trait. For example, the implementation for " @@ -477,12 +570,12 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:238 +#: doc/guide-container.md:285 #, no-wrap msgid "" -"~~~\n" -"impl> FromIterator for ~[A] {\n" -" pub fn from_iterator(iterator: &mut T) -> ~[A] {\n" +"~~~ {.xfail-test}\n" +"impl FromIterator for ~[A] {\n" +" pub fn from_iterator>(iterator: &mut T) -> ~[A] {\n" " let (lower, _) = iterator.size_hint();\n" " let mut xs = with_capacity(lower);\n" " for x in iterator {\n" @@ -495,24 +588,26 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:240 +#: doc/guide-container.md:287 msgid "### Size hints" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:243 +#: doc/guide-container.md:290 msgid "" "The `Iterator` trait provides a `size_hint` default method, returning a " "lower bound and optionally on upper bound on the length of the iterator:" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:247 -msgid "~~~ fn size_hint(&self) -> (uint, Option) { (0, None) } ~~~" +#: doc/guide-container.md:294 +msgid "" +"~~~ {.xfail-test} fn size_hint(&self) -> (uint, Option) { (0, None) } " +"~~~" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:251 +#: doc/guide-container.md:298 msgid "" "The vector implementation of `FromIterator` from above uses the lower bound " "to pre-allocate enough space to hold the minimum number of elements the " @@ -520,20 +615,20 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:254 +#: doc/guide-container.md:301 msgid "" "The default implementation is always correct, but it should be overridden if " "the iterator can provide better information." msgstr "" #. type: Plain text -#: doc/tutorial-container.md:256 +#: doc/guide-container.md:303 msgid "" "The `ZeroStream` from earlier can provide an exact lower and upper bound:" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:267 +#: doc/guide-container.md:315 #, no-wrap msgid "" "impl ZeroStream {\n" @@ -543,7 +638,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:272 +#: doc/guide-container.md:320 #, no-wrap msgid "" " fn size_hint(&self) -> (uint, Option) {\n" @@ -553,12 +648,12 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:286 +#: doc/guide-container.md:334 msgid "## Double-ended iterators" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:290 +#: doc/guide-container.md:338 msgid "" "The `DoubleEndedIterator` trait represents an iterator able to yield " "elements from either end of a range. It inherits from the `Iterator` trait " @@ -566,75 +661,91 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:293 +#: doc/guide-container.md:341 msgid "" "A `DoubleEndedIterator` can be flipped with the `invert` adaptor, returning " "another `DoubleEndedIterator` with `next` and `next_back` exchanged." msgstr "" #. type: Plain text -#: doc/tutorial-container.md:300 +#: doc/guide-container.md:348 msgid "" -"~~~ let xs = [1, 2, 3, 4, 5, 6]; let mut it = xs.iter(); printfln!(\"%?\", " -"it.next()); // prints `Some(&1)` printfln!(\"%?\", it.next()); // prints " -"`Some(&2)` printfln!(\"%?\", it.next_back()); // prints `Some(&6)`" +"~~~ let xs = [1, 2, 3, 4, 5, 6]; let mut it = xs.iter(); println!(\"{:?}\", " +"it.next()); // prints `Some(&1)` println!(\"{:?}\", it.next()); // prints " +"`Some(&2)` println!(\"{:?}\", it.next_back()); // prints `Some(&6)`" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:306 +#: doc/guide-container.md:354 #, no-wrap msgid "" "// prints `5`, `4` and `3`\n" "for &x in it.invert() {\n" -" printfln!(\"%?\", x)\n" +" println!(\"{}\", x)\n" "}\n" "~~~\n" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:309 +#: doc/guide-container.md:357 msgid "" "The `rev_iter` and `mut_rev_iter` methods on vectors just return an inverted " "version of the standard immutable and mutable vector iterators." msgstr "" #. type: Plain text -#: doc/tutorial-container.md:312 +#: doc/guide-container.md:360 msgid "" -"The `chain_`, `transform`, `filter`, `filter_map` and `peek` adaptors are " +"The `chain`, `map`, `filter`, `filter_map` and `inspect` adaptors are " "`DoubleEndedIterator` implementations if the underlying iterators are." msgstr "" #. type: Plain text -#: doc/tutorial-container.md:317 +#: doc/guide-container.md:365 msgid "" "~~~ let xs = [1, 2, 3, 4]; let ys = [5, 6, 7, 8]; let mut it = xs.iter()." -"chain_(ys.iter()).transform(|&x| x * 2);" +"chain(ys.iter()).map(|&x| x * 2);" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:319 -msgid "printfln!(\"%?\", it.next()); // prints `Some(2)`" +#: doc/guide-container.md:367 +msgid "println!(\"{:?}\", it.next()); // prints `Some(2)`" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:325 +#: doc/guide-container.md:373 #, no-wrap msgid "" "// prints `16`, `14`, `12`, `10`, `8`, `6`, `4`\n" "for x in it.invert() {\n" -" printfln!(\"%?\", x);\n" +" println!(\"{}\", x);\n" "}\n" "~~~\n" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:327 +#: doc/guide-container.md:377 +msgid "" +"The `reverse_` method is also available for any double-ended iterator " +"yielding mutable references. It can be used to reverse a container in-place. " +"Note that the trailing underscore is a workaround for issue #5898 and will " +"be removed." +msgstr "" + +#. type: Plain text +#: doc/guide-container.md:383 +msgid "" +"~~~ let mut ys = [1, 2, 3, 4, 5]; ys.mut_iter().reverse_(); assert_eq!(ys, " +"[5, 4, 3, 2, 1]); ~~~" +msgstr "" + +#. type: Plain text +#: doc/guide-container.md:385 msgid "## Random-access iterators" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:331 +#: doc/guide-container.md:389 msgid "" "The `RandomAccessIterator` trait represents an iterator offering random " "access to the whole range. The `indexable` method retrieves the number of " @@ -642,32 +753,33 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:334 +#: doc/guide-container.md:392 msgid "" -"The `chain_` adaptor is an implementation of `RandomAccessIterator` if the " +"The `chain` adaptor is an implementation of `RandomAccessIterator` if the " "underlying iterators are." msgstr "" #. type: Plain text -#: doc/tutorial-container.md:343 +#: doc/guide-container.md:401 msgid "" "~~~ let xs = [1, 2, 3, 4, 5]; let ys = ~[7, 9, 11]; let mut it = xs.iter()." -"chain_(ys.iter()); printfln!(\"%?\", it.idx(0)); // prints `Some(&1)` " -"printfln!(\"%?\", it.idx(5)); // prints `Some(&7)` printfln!(\"%?\", it." -"idx(7)); // prints `Some(&11)` printfln!(\"%?\", it.idx(8)); // prints `None`" +"chain(ys.iter()); println!(\"{:?}\", it.idx(0)); // prints `Some(&1)` " +"println!(\"{:?}\", it.idx(5)); // prints `Some(&7)` println!(\"{:?}\", it." +"idx(7)); // prints `Some(&11)` println!(\"{:?}\", it.idx(8)); // prints " +"`None`" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:348 +#: doc/guide-container.md:406 msgid "" "// yield two elements from the beginning, and one from the end it.next(); it." "next(); it.next_back();" msgstr "" #. type: Plain text -#: doc/tutorial-container.md:352 +#: doc/guide-container.md:410 msgid "" -"printfln!(\"%?\", it.idx(0)); // prints `Some(&3)` printfln!(\"%?\", it." -"idx(4)); // prints `Some(&9)` printfln!(\"%?\", it.idx(6)); // prints `None` " -"~~~" +"println!(\"{:?}\", it.idx(0)); // prints `Some(&3)` println!(\"{:?}\", it." +"idx(4)); // prints `Some(&9)` println!(\"{:?}\", it.idx(6)); // prints " +"`None` ~~~" msgstr "" diff --git a/doc/po/ja/tutorial-ffi.md.po b/doc/po/ja/guide-ffi.md.po similarity index 50% rename from doc/po/ja/tutorial-ffi.md.po rename to doc/po/ja/guide-ffi.md.po index 088970bf00d28..05a4267d48e18 100644 --- a/doc/po/ja/tutorial-ffi.md.po +++ b/doc/po/ja/guide-ffi.md.po @@ -1,13 +1,13 @@ # Japanese translations for Rust package -# Copyright (C) 2013 The Rust Project Developers +# Copyright (C) 2014 The Rust Project Developers # This file is distributed under the same license as the Rust package. -# Automatically generated, 2013. +# Automatically generated, 2014. # msgid "" msgstr "" -"Project-Id-Version: Rust 0.8\n" -"POT-Creation-Date: 2013-08-10 07:44+0900\n" -"PO-Revision-Date: 2013-07-22 23:37+0900\n" +"Project-Id-Version: Rust 0.9\n" +"POT-Creation-Date: 2014-01-10 12:20+0900\n" +"PO-Revision-Date: 2014-01-10 12:20+0900\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" "Language: ja\n" @@ -17,26 +17,23 @@ msgstr "" "Plural-Forms: nplurals=1; plural=0;\n" #. type: Plain text +#: doc/guide-conditions.md:4 doc/guide-ffi.md:4 doc/guide-lifetimes.md:4 +#: doc/guide-macros.md:4 doc/guide-rustpkg.md:4 doc/guide-tasks.md:4 #: doc/rust.md:4 doc/rustpkg.md:4 doc/tutorial.md:4 -#: doc/tutorial-borrowed-ptr.md:4 doc/tutorial-ffi.md:4 -#: doc/tutorial-macros.md:4 doc/tutorial-tasks.md:4 msgid "# Introduction" msgstr "# イントロダクション" #. type: Plain text -#: doc/tutorial.md:868 doc/tutorial-ffi.md:143 -msgid "# Destructors" -msgstr "# デストラクタ" +#: doc/guide-ffi.md:2 +#, fuzzy +#| msgid "[The foreign function interface][ffi]" +msgid "% The Rust Foreign Function Interface Guide" +msgstr "[他言語間インターフェース (foreign function inferface)][ffi]" #. type: Plain text -#: doc/tutorial-ffi.md:2 -msgid "% Rust Foreign Function Interface Tutorial" -msgstr "" - -#. type: Plain text -#: doc/tutorial-ffi.md:10 +#: doc/guide-ffi.md:10 msgid "" -"This tutorial will use the [snappy](https://code.google.com/p/snappy/) " +"This guide will use the [snappy](https://code.google.com/p/snappy/) " "compression/decompression library as an introduction to writing bindings for " "foreign code. Rust is currently unable to call directly into a C++ library, " "but snappy includes a C interface (documented in [`snappy-c.h`](https://code." @@ -44,49 +41,49 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:13 +#: doc/guide-ffi.md:13 msgid "" "The following is a minimal example of calling a foreign function which will " "compile if snappy is installed:" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:16 +#: doc/guide-ffi.md:16 msgid "~~~~ {.xfail-test} use std::libc::size_t;" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:21 +#: doc/guide-ffi.md:21 #, no-wrap msgid "" -"#[link_args = \"-lsnappy\"]\n" +"#[link(name = \"snappy\")]\n" "extern {\n" " fn snappy_max_compressed_length(source_length: size_t) -> size_t;\n" "}\n" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:27 +#: doc/guide-ffi.md:27 #, no-wrap msgid "" "fn main() {\n" " let x = unsafe { snappy_max_compressed_length(100) };\n" -" println(fmt!(\"max compressed length of a 100 byte buffer: %?\", x));\n" +" println!(\"max compressed length of a 100 byte buffer: {}\", x);\n" "}\n" "~~~~\n" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:31 +#: doc/guide-ffi.md:32 msgid "" "The `extern` block is a list of function signatures in a foreign library, in " -"this case with the platform's C ABI. The `#[link_args]` attribute is used to " +"this case with the platform's C ABI. The `#[link(...)]` attribute is used to " "instruct the linker to link against the snappy library so the symbols are " "resolved." msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:37 +#: doc/guide-ffi.md:39 msgid "" "Foreign functions are assumed to be unsafe so calls to them need to be " "wrapped with `unsafe {}` as a promise to the compiler that everything " @@ -97,28 +94,28 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:41 +#: doc/guide-ffi.md:43 msgid "" "When declaring the argument types to a foreign function, the Rust compiler " -"will not check if the declaration is correct, so specifying it correctly is " +"can not check if the declaration is correct, so specifying it correctly is " "part of keeping the binding correct at runtime." msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:43 +#: doc/guide-ffi.md:45 msgid "The `extern` block can be extended to cover the entire snappy API:" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:46 +#: doc/guide-ffi.md:48 msgid "~~~~ {.xfail-test} use std::libc::{c_int, size_t};" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:65 +#: doc/guide-ffi.md:67 #, no-wrap msgid "" -"#[link_args = \"-lsnappy\"]\n" +"#[link(name = \"snappy\")]\n" "extern {\n" " fn snappy_compress(input: *u8,\n" " input_length: size_t,\n" @@ -139,12 +136,12 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:67 +#: doc/guide-ffi.md:69 msgid "# Creating a safe interface" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:71 +#: doc/guide-ffi.md:73 msgid "" "The raw C API needs to be wrapped to provide memory safety and make use of " "higher-level concepts like vectors. A library can choose to expose only the " @@ -152,7 +149,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:76 +#: doc/guide-ffi.md:78 msgid "" "Wrapping the functions which expect buffers involves using the `vec::raw` " "module to manipulate Rust vectors as pointers to memory. Rust's vectors are " @@ -162,7 +159,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:84 +#: doc/guide-ffi.md:86 #, no-wrap msgid "" "~~~~ {.xfail-test}\n" @@ -175,7 +172,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:88 +#: doc/guide-ffi.md:90 msgid "" "The `validate_compressed_buffer` wrapper above makes use of an `unsafe` " "block, but it makes the guarantee that calling it is safe for all inputs by " @@ -183,14 +180,14 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:91 +#: doc/guide-ffi.md:93 msgid "" "The `snappy_compress` and `snappy_uncompress` functions are more complex, " "since a buffer has to be allocated to hold the output too." msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:96 +#: doc/guide-ffi.md:98 msgid "" "The `snappy_max_compressed_length` function can be used to allocate a vector " "with the maximum required capacity to hold the compressed output. The vector " @@ -200,7 +197,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:102 +#: doc/guide-ffi.md:104 #, no-wrap msgid "" "~~~~ {.xfail-test}\n" @@ -211,7 +208,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:106 +#: doc/guide-ffi.md:108 #, no-wrap msgid "" " let mut dstlen = snappy_max_compressed_length(srclen);\n" @@ -220,7 +217,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:113 +#: doc/guide-ffi.md:115 #, no-wrap msgid "" " snappy_compress(psrc, srclen, pdst, &mut dstlen);\n" @@ -232,7 +229,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:116 +#: doc/guide-ffi.md:118 msgid "" "Decompression is similar, because snappy stores the uncompressed size as " "part of the compression format and `snappy_uncompressed_length` will " @@ -240,7 +237,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:122 +#: doc/guide-ffi.md:124 #, no-wrap msgid "" "~~~~ {.xfail-test}\n" @@ -251,7 +248,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:125 +#: doc/guide-ffi.md:127 #, no-wrap msgid "" " let mut dstlen: size_t = 0;\n" @@ -259,7 +256,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:128 +#: doc/guide-ffi.md:130 #, no-wrap msgid "" " let mut dst = vec::with_capacity(dstlen as uint);\n" @@ -267,7 +264,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:138 +#: doc/guide-ffi.md:140 #, no-wrap msgid "" " if snappy_uncompress(psrc, srclen, pdst, &mut dstlen) == 0 {\n" @@ -282,54 +279,108 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:141 +#: doc/guide-ffi.md:143 msgid "" "For reference, the examples used here are also available as an [library on " "GitHub](https://github.com/thestinger/rust-snappy)." msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:147 +#: doc/guide-ffi.md:145 +msgid "# Stack management" +msgstr "" + +#. type: Plain text +#: doc/guide-ffi.md:152 +msgid "" +"Rust tasks by default run on a \"large stack\". This is actually implemented " +"as a reserving a large segment of the address space and then lazily mapping " +"in pages as they are needed. When calling an external C function, the code " +"is invoked on the same stack as the rust stack. This means that there is no " +"extra stack-switching mechanism in place because it is assumed that the " +"large stack for the rust task is plenty for the C function to have." +msgstr "" + +#. type: Plain text +#: doc/guide-ffi.md:159 +msgid "" +"A planned future improvement (net yet implemented at the time of this " +"writing) is to have a guard page at the end of every rust stack. No rust " +"function will hit this guard page (due to Rust's usage of LLVM's " +"`__morestack`). The intention for this unmapped page is to prevent infinite " +"recursion in C from overflowing onto other rust stacks. If the guard page is " +"hit, then the process will be terminated with a message saying that the " +"guard page was hit." +msgstr "" + +#. type: Plain text +#: doc/guide-ffi.md:166 msgid "" -"Foreign libraries often hand off ownership of resources to the calling code, " -"which should be wrapped in a destructor to provide safety and guarantee " -"their release." +"For normal external function usage, this all means that there shouldn't be " +"any need for any extra effort on a user's perspective. The C stack naturally " +"interleaves with the rust stack, and it's \"large enough\" for both to " +"interoperate. If, however, it is determined that a larger stack is " +"necessary, there are appropriate functions in the task spawning API to " +"control the size of the stack of the task which is spawned." msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:150 +#: doc/guide-ffi.md:168 doc/tutorial.md:875 +msgid "# Destructors" +msgstr "# デストラクタ" + +#. type: Plain text +#: doc/guide-ffi.md:172 msgid "" -"A type with the same functionality as owned boxes can be implemented by " -"wrapping `malloc` and `free`:" +"Foreign libraries often hand off ownership of resources to the calling " +"code. When this occurs, we must use Rust's destructors to provide safety " +"and guarantee the release of these resources (especially in the case of " +"failure)." msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:156 +#: doc/guide-ffi.md:175 +msgid "" +"As an example, we give a reimplementation of owned boxes by wrapping " +"`malloc` and `free`:" +msgstr "" + +#. type: Plain text +#: doc/guide-ffi.md:181 msgid "" "~~~~ use std::cast; use std::libc::{c_void, size_t, malloc, free}; use std::" "ptr; use std::unstable::intrinsics;" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:161 +#: doc/guide-ffi.md:188 #, no-wrap msgid "" -"// a wrapper around the handle returned by the foreign code\n" +"// Define a wrapper around the handle returned by the foreign code.\n" +"// Unique has the same semantics as ~T\n" "pub struct Unique {\n" +" // It contains a single raw, mutable pointer to the object in question.\n" " priv ptr: *mut T\n" "}\n" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:172 +#: doc/guide-ffi.md:206 #, no-wrap msgid "" +"// Implement methods for creating and using the values in the box.\n" +"// NB: For simplicity and correctness, we require that T has kind Send\n" +"// (owned boxes relax this restriction, and can contain managed (GC) boxes).\n" +"// This is because, as implemented, the garbage collector would not know\n" +"// about any shared boxes stored in the malloc'd region of memory.\n" "impl Unique {\n" " pub fn new(value: T) -> Unique {\n" " unsafe {\n" " let ptr = malloc(std::mem::size_of::() as size_t) as *mut T;\n" " assert!(!ptr::is_null(ptr));\n" " // `*ptr` is uninitialized, and `*ptr = value` would attempt to destroy it\n" +" // move_val_init moves a value into this memory without\n" +" // attempting to drop the original value.\n" " intrinsics::move_val_init(&mut *ptr, value);\n" " Unique{ptr: ptr}\n" " }\n" @@ -337,7 +388,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:177 +#: doc/guide-ffi.md:211 #, no-wrap msgid "" " // the 'r lifetime results in the same semantics as `&*x` with ~T\n" @@ -347,7 +398,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:183 +#: doc/guide-ffi.md:217 #, no-wrap msgid "" " // the 'r lifetime results in the same semantics as `&mut *x` with ~T\n" @@ -358,15 +409,23 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:195 +#: doc/guide-ffi.md:237 #, no-wrap msgid "" +"// The key ingredient for safety, we associate a destructor with\n" +"// Unique, making the struct manage the raw pointer: when the\n" +"// struct goes out of scope, it will automatically free the raw pointer.\n" +"// NB: This is an unsafe destructor, because rustc will not normally\n" +"// allow destructors to be associated with parametrized types, due to\n" +"// bad interaction with managed boxes. (With the Send restriction,\n" +"// we don't have this problem.)\n" "#[unsafe_destructor]\n" "impl Drop for Unique {\n" -" fn drop(&self) {\n" +" fn drop(&mut self) {\n" " unsafe {\n" -" let x = intrinsics::init(); // dummy value to swap in\n" -" // moving the object out is needed to call the destructor\n" +" let x = intrinsics::uninit(); // dummy value to swap in\n" +" // We need to move the object out of the box, so that\n" +" // the destructor is called (at the end of this scope.)\n" " ptr::replace_ptr(self.ptr, x);\n" " free(self.ptr as *c_void)\n" " }\n" @@ -375,7 +434,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:202 +#: doc/guide-ffi.md:244 #, no-wrap msgid "" "// A comparison between the built-in ~ and this reimplementation\n" @@ -387,7 +446,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:209 +#: doc/guide-ffi.md:251 #, no-wrap msgid "" " {\n" @@ -399,25 +458,152 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:211 +#: doc/guide-ffi.md:253 msgid "# Linking" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:215 +#: doc/guide-ffi.md:257 +msgid "" +"The `link` attribute on `extern` blocks provides the basic building block " +"for instructing rustc how it will link to native libraries. There are two " +"accepted forms of the link attribute today:" +msgstr "" + +#. type: Bullet: '* ' +#: doc/guide-ffi.md:260 +msgid "`#[link(name = \"foo\")]`" +msgstr "" + +#. type: Bullet: '* ' +#: doc/guide-ffi.md:260 +msgid "`#[link(name = \"foo\", kind = \"bar\")]`" +msgstr "" + +#. type: Plain text +#: doc/guide-ffi.md:265 +msgid "" +"In both of these cases, `foo` is the name of the native library that we're " +"linking to, and in the second case `bar` is the type of native library that " +"the compiler is linking to. There are currently three known types of native " +"libraries:" +msgstr "" + +#. type: Bullet: '* ' +#: doc/guide-ffi.md:269 +msgid "Dynamic - `#[link(name = \"readline\")]" +msgstr "" + +#. type: Bullet: '* ' +#: doc/guide-ffi.md:269 +msgid "Static - `#[link(name = \"my_build_dependency\", kind = \"static\")]" +msgstr "" + +#. type: Bullet: '* ' +#: doc/guide-ffi.md:269 +msgid "Frameworks - `#[link(name = \"CoreFoundation\", kind = \"framework\")]" +msgstr "" + +#. type: Plain text +#: doc/guide-ffi.md:271 +msgid "Note that frameworks are only available on OSX targets." +msgstr "" + +#. type: Plain text +#: doc/guide-ffi.md:277 +msgid "" +"The different `kind` values are meant to differentiate how the native " +"library participates in linkage. From a linkage perspective, the rust " +"compiler creates two flavors of artifacts: partial (rlib/staticlib) and " +"final (dylib/binary). Native dynamic libraries and frameworks are " +"propagated to the final artifact boundary, while static libraries are not " +"propagated at all." +msgstr "" + +#. type: Plain text +#: doc/guide-ffi.md:279 +msgid "A few examples of how this model can be used are:" +msgstr "" + +#. type: Bullet: '* ' +#: doc/guide-ffi.md:285 +msgid "" +"A native build dependency. Sometimes some C/C++ glue is needed when writing " +"some rust code, but distribution of the C/C++ code in a library format is " +"just a burden. In this case, the code will be archived into `libfoo.a` and " +"then the rust crate would declare a dependency via `#[link(name = \"foo\", " +"kind = \"static\")]`." +msgstr "" + +#. type: Plain text +#: doc/guide-ffi.md:289 +#, no-wrap +msgid "" +" Regardless of the flavor of output for the crate, the native static library\n" +" will be included in the output, meaning that distribution of the native static\n" +" library is not necessary.\n" +msgstr "" + +#. type: Bullet: '* ' +#: doc/guide-ffi.md:296 +msgid "" +"A normal dynamic dependency. Common system libraries (like `readline`) are " +"available on a large number of systems, and often a static copy of these " +"libraries cannot be found. When this dependency is included in a rust crate, " +"partial targets (like rlibs) will not link to the library, but when the rlib " +"is included in a final target (like a binary), the native library will be " +"linked in." +msgstr "" + +#. type: Plain text +#: doc/guide-ffi.md:298 +msgid "On OSX, frameworks behave with the same semantics as a dynamic library." +msgstr "" + +#. type: Plain text +#: doc/guide-ffi.md:300 +msgid "## The `link_args` attribute" +msgstr "" + +#. type: Plain text +#: doc/guide-ffi.md:305 msgid "" -"In addition to the `#[link_args]` attribute for explicitly passing arguments " -"to the linker, an `extern mod` block will pass `-lmodname` to the linker by " -"default unless it has a `#[nolink]` attribute applied." +"There is one other way to tell rustc how to customize linking, and that is " +"via the `link_args` attribute. This attribute is applied to `extern` blocks " +"and specifies raw flags which need to get passed to the linker when " +"producing an artifact. An example usage would be:" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:217 +#: doc/guide-ffi.md:310 +msgid "~~~ {.xfail-test} #[link_args = \"-foo -bar -baz\"] extern {} ~~~" +msgstr "" + +#. type: Plain text +#: doc/guide-ffi.md:317 +msgid "" +"Note that this feature is currently hidden behind the `feature(link_args)` " +"gate because this is not a sanctioned way of performing linking. Right now " +"rustc shells out to the system linker, so it makes sense to provide extra " +"command line arguments, but this will not always be the case. In the future " +"rustc may use LLVM directly to link native libraries in which case " +"`link_args` will have no meaning." +msgstr "" + +#. type: Plain text +#: doc/guide-ffi.md:320 +msgid "" +"It is highly recommended to *not* use this attribute, and rather use the " +"more formal `#[link(...)]` attribute on `extern` blocks instead." +msgstr "" + +#. type: Plain text +#: doc/guide-ffi.md:322 msgid "# Unsafe blocks" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:221 +#: doc/guide-ffi.md:326 msgid "" "Some operations, like dereferencing unsafe pointers or calling functions " "that have been marked unsafe are only allowed inside unsafe blocks. Unsafe " @@ -426,31 +612,36 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:224 +#: doc/guide-ffi.md:329 msgid "" "Unsafe functions, on the other hand, advertise it to the world. An unsafe " "function is written like this:" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:228 +#: doc/guide-ffi.md:333 +#, fuzzy +#| msgid "~~~~ let square = |x: int| -> uint { (x * x) as uint }; ~~~~" msgid "~~~~ unsafe fn kaboom(ptr: *int) -> int { *ptr } ~~~~" msgstr "" +"~~~~\n" +"let square = |x: int| -> uint { (x * x) as uint };\n" +"~~~~~~~~\n" #. type: Plain text -#: doc/tutorial-ffi.md:230 +#: doc/guide-ffi.md:335 msgid "" "This function can only be called from an `unsafe` block or another `unsafe` " "function." msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:232 +#: doc/guide-ffi.md:337 msgid "# Accessing foreign globals" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:236 +#: doc/guide-ffi.md:341 msgid "" "Foreign APIs often export a global variable which could do something like " "track global state. In order to access these variables, you declare them in " @@ -458,33 +649,33 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:239 +#: doc/guide-ffi.md:344 msgid "~~~{.xfail-test} use std::libc;" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:244 +#: doc/guide-ffi.md:349 #, no-wrap msgid "" -"#[link_args = \"-lreadline\"]\n" +"#[link(name = \"readline\")]\n" "extern {\n" " static rl_readline_version: libc::c_int;\n" "}\n" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:250 +#: doc/guide-ffi.md:355 #, no-wrap msgid "" "fn main() {\n" -" println(fmt!(\"You have readline version %d installed.\",\n" -" rl_readline_version as int));\n" +" println!(\"You have readline version {} installed.\",\n" +" rl_readline_version as int);\n" "}\n" "~~~\n" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:254 +#: doc/guide-ffi.md:359 msgid "" "Alternatively, you may need to alter global state provided by a foreign " "interface. To do this, statics can be declared with `mut` so rust can mutate " @@ -492,22 +683,22 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:258 +#: doc/guide-ffi.md:363 msgid "~~~{.xfail-test} use std::libc; use std::ptr;" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:263 +#: doc/guide-ffi.md:368 #, no-wrap msgid "" -"#[link_args = \"-lreadline\"]\n" +"#[link(name = \"readline\")]\n" "extern {\n" " static mut rl_prompt: *libc::c_char;\n" "}\n" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:272 +#: doc/guide-ffi.md:377 #, no-wrap msgid "" "fn main() {\n" @@ -521,49 +712,99 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:274 +#: doc/guide-ffi.md:379 msgid "# Foreign calling conventions" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:279 +#: doc/guide-ffi.md:383 msgid "" "Most foreign code exposes a C ABI, and Rust uses the platform's C calling " "convention by default when calling foreign functions. Some foreign " "functions, most notably the Windows API, use other calling conventions. Rust " -"provides the `abi` attribute as a way to hint to the compiler which calling " -"convention to use:" +"provides a way to tell the compiler which convention to use:" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:288 +#: doc/guide-ffi.md:391 #, no-wrap msgid "" "~~~~\n" -"#[cfg(target_os = \"win32\")]\n" -"#[abi = \"stdcall\"]\n" +"#[cfg(target_os = \"win32\", target_arch = \"x86\")]\n" "#[link_name = \"kernel32\"]\n" -"extern {\n" -" fn SetEnvironmentVariableA(n: *u8, v: *u8) -> int;\n" +"extern \"stdcall\" {\n" +" fn SetEnvironmentVariableA(n: *u8, v: *u8) -> std::libc::c_int;\n" "}\n" "~~~~\n" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:292 +#: doc/guide-ffi.md:394 +msgid "" +"This applies to the entire `extern` block. The list of supported ABI " +"constraints are:" +msgstr "" + +#. type: Bullet: '* ' +#: doc/guide-ffi.md:403 +msgid "`stdcall`" +msgstr "" + +#. type: Bullet: '* ' +#: doc/guide-ffi.md:403 +msgid "`aapcs`" +msgstr "" + +#. type: Bullet: '* ' +#: doc/guide-ffi.md:403 +msgid "`cdecl`" +msgstr "" + +#. type: Bullet: '* ' +#: doc/guide-ffi.md:403 +msgid "`fastcall`" +msgstr "" + +#. type: Bullet: '* ' +#: doc/guide-ffi.md:403 +msgid "`Rust`" +msgstr "" + +#. type: Bullet: '* ' +#: doc/guide-ffi.md:403 +msgid "`rust-intrinsic`" +msgstr "" + +#. type: Bullet: '* ' +#: doc/guide-ffi.md:403 +msgid "`system`" +msgstr "" + +#. type: Bullet: '* ' +#: doc/guide-ffi.md:403 +msgid "`C`" +msgstr "" + +#. type: Plain text +#: doc/guide-ffi.md:411 msgid "" -"The `abi` attribute applies to a foreign module (it cannot be applied to a " -"single function within a module), and must be either `\"cdecl\"` or `" -"\"stdcall\"`. The compiler may eventually support other calling conventions." +"Most of the abis in this list are self-explanatory, but the `system` abi may " +"seem a little odd. This constraint selects whatever the appropriate ABI is " +"for interoperating with the target's libraries. For example, on win32 with a " +"x86 architecture, this means that the abi used would be `stdcall`. On " +"x86_64, however, windows uses the `C` calling convention, so `C` would be " +"used. This means that in our previous example, we could have used `extern " +"\"system\" { ... }` to define a block for all windows systems, not just x86 " +"ones." msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:294 +#: doc/guide-ffi.md:413 msgid "# Interoperability with foreign code" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:298 +#: doc/guide-ffi.md:417 msgid "" "Rust guarantees that the layout of a `struct` is compatible with the " "platform's representation in C. A `#[packed]` attribute is available, which " @@ -572,29 +813,28 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:305 +#: doc/guide-ffi.md:424 msgid "" "Rust's owned and managed boxes use non-nullable pointers as handles which " "point to the contained object. However, they should not be manually created " -"because they are managed by internal allocators. Borrowed pointers can " -"safely be assumed to be non-nullable pointers directly to the type. However, " -"breaking the borrow checking or mutability rules is not guaranteed to be " -"safe, so prefer using raw pointers (`*`) if that's needed because the " -"compiler can't make as many assumptions about them." +"because they are managed by internal allocators. References can safely be " +"assumed to be non-nullable pointers directly to the type. However, breaking " +"the borrow checking or mutability rules is not guaranteed to be safe, so " +"prefer using raw pointers (`*`) if that's needed because the compiler can't " +"make as many assumptions about them." msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:310 +#: doc/guide-ffi.md:428 msgid "" "Vectors and strings share the same basic memory layout, and utilities are " -"available in the `vec` and `str` modules for working with C APIs. Strings " -"are terminated with `\\0` for interoperability with C, but it should not be " -"assumed because a slice will not always be nul-terminated. Instead, the " -"`str::as_c_str` function should be used." +"available in the `vec` and `str` modules for working with C APIs. However, " +"strings are not terminated with `\\0`. If you need a NUL-terminated string " +"for interoperability with C, you should use the `c_str::to_c_str` function." msgstr "" #. type: Plain text -#: doc/tutorial-ffi.md:312 +#: doc/guide-ffi.md:430 msgid "" "The standard library includes type aliases and function definitions for the " "C standard library in the `libc` module, and Rust links against `libc` and " diff --git a/doc/po/ja/tutorial-borrowed-ptr.md.po b/doc/po/ja/guide-lifetimes.md.po similarity index 55% rename from doc/po/ja/tutorial-borrowed-ptr.md.po rename to doc/po/ja/guide-lifetimes.md.po index 19bf3adeb0b24..1a1a637b0ec6c 100644 --- a/doc/po/ja/tutorial-borrowed-ptr.md.po +++ b/doc/po/ja/guide-lifetimes.md.po @@ -1,13 +1,13 @@ # Japanese translations for Rust package -# Copyright (C) 2013 The Rust Project Developers +# Copyright (C) 2014 The Rust Project Developers # This file is distributed under the same license as the Rust package. -# Automatically generated, 2013. +# Automatically generated, 2014. # msgid "" msgstr "" -"Project-Id-Version: Rust 0.8\n" -"POT-Creation-Date: 2013-07-22 23:37+0900\n" -"PO-Revision-Date: 2013-07-28 20:32+0900\n" +"Project-Id-Version: Rust 0.9\n" +"POT-Creation-Date: 2014-01-10 12:20+0900\n" +"PO-Revision-Date: 2014-01-10 12:20+0900\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" "Language: ja\n" @@ -17,100 +17,121 @@ msgstr "" "Plural-Forms: nplurals=1; plural=0;\n" #. type: Plain text +#: doc/guide-conditions.md:4 doc/guide-ffi.md:4 doc/guide-lifetimes.md:4 +#: doc/guide-macros.md:4 doc/guide-rustpkg.md:4 doc/guide-tasks.md:4 #: doc/rust.md:4 doc/rustpkg.md:4 doc/tutorial.md:4 -#: doc/tutorial-borrowed-ptr.md:4 doc/tutorial-ffi.md:4 -#: doc/tutorial-macros.md:4 doc/tutorial-tasks.md:4 msgid "# Introduction" msgstr "# イントロダクション" #. type: Plain text -#: doc/tutorial.md:1108 doc/tutorial-borrowed-ptr.md:72 -msgid "Now we can call `compute_distance()` in various ways:" -msgstr "" -"上記の `compute_distance()` 関数は、様々な方法で呼び出すことができます。" - -#. type: Plain text -#: doc/tutorial-borrowed-ptr.md:2 -msgid "% Rust Borrowed Pointers Tutorial" +#: doc/guide-lifetimes.md:2 +msgid "% The Rust References and Lifetimes Guide" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:14 +#: doc/guide-lifetimes.md:14 msgid "" -"Borrowed pointers are one of the more flexible and powerful tools available " -"in Rust. A borrowed pointer can point anywhere: into the managed or exchange " -"heap, into the stack, and even into the interior of another data structure. " -"A borrowed pointer is as flexible as a C pointer or C++ reference. However, " -"unlike C and C++ compilers, the Rust compiler includes special static checks " -"that ensure that programs use borrowed pointers safely. Another advantage of " -"borrowed pointers is that they are invisible to the garbage collector, so " -"working with borrowed pointers helps reduce the overhead of automatic memory " -"management." +"References are one of the more flexible and powerful tools available in " +"Rust. A reference can point anywhere: into the managed or exchange heap, " +"into the stack, and even into the interior of another data structure. A " +"reference is as flexible as a C pointer or C++ reference. However, unlike C " +"and C++ compilers, the Rust compiler includes special static checks that " +"ensure that programs use references safely. Another advantage of references " +"is that they are invisible to the garbage collector, so working with " +"references helps reduce the overhead of automatic memory management." msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:18 +#: doc/guide-lifetimes.md:18 msgid "" -"Despite their complete safety, a borrowed pointer's representation at " -"runtime is the same as that of an ordinary pointer in a C program. They " -"introduce zero overhead. The compiler does all safety checks at compile time." +"Despite their complete safety, a reference's representation at runtime is " +"the same as that of an ordinary pointer in a C program. They introduce zero " +"overhead. The compiler does all safety checks at compile time." msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:24 +#: doc/guide-lifetimes.md:24 msgid "" -"Although borrowed pointers have rather elaborate theoretical underpinnings " -"(region pointers), the core concepts will be familiar to anyone who has " -"worked with C or C++. Therefore, the best way to explain how they are used—" -"and their limitations—is probably just to work through several examples." +"Although references have rather elaborate theoretical underpinnings (region " +"pointers), the core concepts will be familiar to anyone who has worked with " +"C or C++. Therefore, the best way to explain how they are used—and their " +"limitations—is probably just to work through several examples." msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:26 +#: doc/guide-lifetimes.md:26 +#, fuzzy +#| msgid "## A minimal example" msgid "# By example" -msgstr "" +msgstr "## 最小限の例" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:31 +#: doc/guide-lifetimes.md:31 msgid "" -"Borrowed pointers are called *borrowed* because they are only valid for a " -"limited duration. Borrowed pointers never claim any kind of ownership over " -"the data that they point to: instead, they are used for cases where you " -"would like to use data for a short time." +"References, sometimes known as *borrowed pointers*, are only valid for a " +"limited duration. References never claim any kind of ownership over the data " +"that they point to: instead, they are used for cases where you would like to " +"use data for a short time." msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:33 +#: doc/guide-lifetimes.md:33 +#, fuzzy +#| msgid "As an example, consider a simple struct type, `Point`:" msgid "As an example, consider a simple struct type `Point`:" -msgstr "" +msgstr "例として、シンプルな構造体型の `Point` について考えます。" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:37 -msgid "~~~ struct Point {x: float, y: float} ~~~" +#: doc/guide-lifetimes.md:37 +msgid "~~~ struct Point {x: f64, y: f64} ~~~" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:41 +#: doc/guide-lifetimes.md:41 +#, fuzzy +#| msgid "" +#| "We can use this simple definition to allocate points in many different " +#| "ways. For example, in this code, each of these three local variables " +#| "contains a point, but allocated in a different location:" msgid "" "We can use this simple definition to allocate points in many different ways. " "For example, in this code, each of these three local variables contains a " "point, but allocated in a different place:" msgstr "" +"シンプルな定義ですが、この定義を使って `Point` 型のオブジェクトを様々な方法で" +"割り当てることができます。例えば、このコードの3つのローカル変数は、それぞれ異" +"なった場所に `Point` 型のオブジェクトを割り当てています。" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:48 -#, no-wrap +#: doc/guide-lifetimes.md:48 +#, fuzzy, no-wrap +#| msgid "~~~~ {.xfail-test} # struct Point { x: f64, y: f64 } let mut mypoint = Point { x: 1.0, y: 1.0 }; let origin = Point { x: 0.0, y: 0.0 };" msgid "" "~~~\n" -"# struct Point {x: float, y: float}\n" +"# struct Point {x: f64, y: f64}\n" "let on_the_stack : Point = Point {x: 3.0, y: 4.0};\n" "let managed_box : @Point = @Point {x: 5.0, y: 1.0};\n" "let owned_box : ~Point = ~Point {x: 7.0, y: 9.0};\n" "~~~\n" msgstr "" - -#. type: Plain text -#: doc/tutorial-borrowed-ptr.md:60 +"~~~~ {.xfail-test}\n" +"# struct Point { x: f64, y: f64 }\n" +"let mut mypoint = Point { x: 1.0, y: 1.0 };\n" +"let origin = Point { x: 0.0, y: 0.0 };" + +#. type: Plain text +#: doc/guide-lifetimes.md:60 +#, fuzzy +#| msgid "" +#| "Suppose we want to write a procedure that computes the distance between " +#| "any two points, no matter where they are stored. For example, we might " +#| "like to compute the distance between `on_the_stack` and `managed_box`, or " +#| "between `managed_box` and `owned_box`. One option is to define a function " +#| "that takes two arguments of type point—that is, it takes the points by " +#| "value. But this will cause the points to be copied when we call the " +#| "function. For points, this is probably not so bad, but often copies are " +#| "expensive. So we’d like to define a function that takes the points by " +#| "pointer. We can use borrowed pointers to do this:" msgid "" "Suppose we wanted to write a procedure that computed the distance between " "any two points, no matter where they were stored. For example, we might like " @@ -121,18 +142,28 @@ msgid "" "copied. For points, this is probably not so bad, but often copies are " "expensive. Worse, if the data type contains mutable fields, copying can " "change the semantics of your program in unexpected ways. So we'd like to " -"define a function that takes the points by pointer. We can use borrowed " -"pointers to do this:" -msgstr "" - -#. type: Plain text -#: doc/tutorial-borrowed-ptr.md:70 +"define a function that takes the points by pointer. We can use references to " +"do this:" +msgstr "" +"`Point` 型のオブジェクトの割り当て先がどこであったとしても利用可能な、任意の " +"2 点間の距離を計算する処理を書きたいとします。例えば、 `on_the_stack`, " +"`managed_box` 間や `managed_box`, `owned_box` 間の距離を計算する処理です。 1" +"つ目の実装方法として、2つの `Point` 型オブジェクトを引数にとる関数を定義する" +"方法、すなわち、オブジェクトを値で受け渡す方法があります。しかし、この方法で" +"は関数呼び出し時に `Point` オブジェクトのコピーが行われます。`Point` オブジェ" +"クトの場合、このような実装はそれほど悪いものではないでしょうが、コピー処理の" +"コストは高い場合もあります。したがって、`Point` オブジェクトをポインタ渡しす" +"る関数を定義する必要があります。そのために、借用ポインタを利用することが可能" +"です。" + +#. type: Plain text +#: doc/guide-lifetimes.md:70 #, no-wrap msgid "" "~~~\n" -"# struct Point {x: float, y: float}\n" -"# fn sqrt(f: float) -> float { 0f }\n" -"fn compute_distance(p1: &Point, p2: &Point) -> float {\n" +"# struct Point {x: f64, y: f64}\n" +"# fn sqrt(f: f64) -> f64 { 0.0 }\n" +"fn compute_distance(p1: &Point, p2: &Point) -> f64 {\n" " let x_d = p1.x - p2.x;\n" " let y_d = p1.y - p2.y;\n" " sqrt(x_d * x_d + y_d * y_d)\n" @@ -141,22 +172,35 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:82 +#: doc/guide-lifetimes.md:72 doc/tutorial.md:1394 +msgid "Now we can call `compute_distance()` in various ways:" +msgstr "" +"上記の `compute_distance()` 関数は、様々な方法で呼び出すことができます。" + +#. type: Plain text +#: doc/guide-lifetimes.md:82 #, no-wrap msgid "" "~~~\n" -"# struct Point {x: float, y: float}\n" +"# struct Point {x: f64, y: f64}\n" "# let on_the_stack : Point = Point{x: 3.0, y: 4.0};\n" "# let managed_box : @Point = @Point{x: 5.0, y: 1.0};\n" "# let owned_box : ~Point = ~Point{x: 7.0, y: 9.0};\n" -"# fn compute_distance(p1: &Point, p2: &Point) -> float { 0f }\n" +"# fn compute_distance(p1: &Point, p2: &Point) -> f64 { 0.0 }\n" "compute_distance(&on_the_stack, managed_box);\n" "compute_distance(managed_box, owned_box);\n" "~~~\n" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:89 +#: doc/guide-lifetimes.md:89 +#, fuzzy +#| msgid "" +#| "Here the `&` operator is used to take the address of the variable " +#| "`on_the_stack`; this is because `on_the_stack` has the type `Point` (that " +#| "is, a struct value) and we have to take its address to get a value. We " +#| "also call this _borrowing_ the local variable `on_the_stack`, because we " +#| "are creating an alias: that is, another route to the same data." msgid "" "Here, the `&` operator takes the address of the variable `on_the_stack`; " "this is because `on_the_stack` has the type `Point` (that is, a struct " @@ -164,19 +208,47 @@ msgid "" "_borrowing_ the local variable `on_the_stack`, because we have created an " "alias: that is, another name for the same data." msgstr "" +"ここで `&` 演算子は `on_the_stack` 変数のアドレスを取得するために使われていま" +"す。これは、 `on_the_stack` の型は `Point` (つまり、構造体の値) であり、呼び" +"出した関数から値を取得させるため、構造体のアドレスを渡す必要があるからです。" +"値の別名 (エイリアス)、すなわち、同じデータへアクセスするための別の方法を提供" +"するので、このような操作のことをローカル変数 `on_the_stack` の __借用__ " +"(_borrowing_) と呼びます。" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:95 +#: doc/guide-lifetimes.md:95 +#, fuzzy +#| msgid "" +#| "In the case of the boxes `managed_box` and `owned_box`, however, no " +#| "explicit action is necessary. The compiler will automatically convert a " +#| "box like `@point` or `~point` to a borrowed pointer like `&point`. This " +#| "is another form of borrowing; in this case, the contents of the managed/" +#| "owned box are being lent out." msgid "" "In contrast, we can pass the boxes `managed_box` and `owned_box` to " "`compute_distance` directly. The compiler automatically converts a box like " -"`@Point` or `~Point` to a borrowed pointer like `&Point`. This is another " -"form of borrowing: in this case, the caller lends the contents of the " -"managed or owned box to the callee." -msgstr "" - -#. type: Plain text -#: doc/tutorial-borrowed-ptr.md:105 +"`@Point` or `~Point` to a reference like `&Point`. This is another form of " +"borrowing: in this case, the caller lends the contents of the managed or " +"owned box to the callee." +msgstr "" +"ボックスである `managed_box` と `owned_box` の場合は、特に明示的な操作を行う" +"必要はありません。コンパイラは `@point` や `~point` のようなボックスを自動的" +"に `&point` のような借用ポインタへと変換します。これは、別の形態の借用 " +"(borrowing) です。この場合、マネージド/所有ボックスの内容が貸し出されていま" +"す。" + +#. type: Plain text +#: doc/guide-lifetimes.md:105 +#, fuzzy +#| msgid "" +#| "Whenever a value is borrowed, there are some limitations on what you can " +#| "do with the original. For example, if the contents of a variable have " +#| "been lent out, you cannot send that variable to another task, nor will " +#| "you be permitted to take actions that might cause the borrowed value to " +#| "be freed or to change its type. This rule should make intuitive sense: " +#| "you must wait for a borrowed value to be returned (that is, for the " +#| "borrowed pointer to go out of scope) before you can make full use of it " +#| "again." msgid "" "Whenever a caller lends data to a callee, there are some limitations on what " "the caller can do with the original. For example, if the contents of a " @@ -185,45 +257,69 @@ msgid "" "value to be freed or overwrite its component fields with values of different " "types (I'll get into what kinds of actions those are shortly). This rule " "should make intuitive sense: you must wait for a borrower to return the " -"value that you lent it (that is, wait for the borrowed pointer to go out of " -"scope) before you can make full use of it again." +"value that you lent it (that is, wait for the reference to go out of scope) " +"before you can make full use of it again." msgstr "" +"値が借用されている間、借用元の値に対して行える操作がいくらか制限されます。例" +"えば、変数の内容が貸し出された場合、その変数を他のタスクに送信することはでき" +"ませんし、借用された値を解放したり、型が変化させるような操作も行うことができ" +"ません。このルールは理にかなったものでしょう。貸し出した値を最大限に活用する " +"(make full use of it) ためには、貸し出した値の返却 (借用ポインタが存在するス" +"コープを抜ける) を待たなければなりません。" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:107 +#: doc/guide-lifetimes.md:107 msgid "# Other uses for the & operator" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:109 +#: doc/guide-lifetimes.md:109 msgid "In the previous example, the value `on_the_stack` was defined like so:" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:114 +#: doc/guide-lifetimes.md:114 +#, fuzzy +#| msgid "" +#| "~~~ # struct Point { x: f64, y: f64 } let point = &@~Point { x: 10f, y: " +#| "20f }; println(fmt!(\"%f\", point.x)); ~~~" msgid "" -"~~~ # struct Point {x: float, y: float} let on_the_stack: Point = Point {x: " -"3.0, y: 4.0}; ~~~" +"~~~ # struct Point {x: f64, y: f64} let on_the_stack: Point = Point {x: 3.0, " +"y: 4.0}; ~~~" msgstr "" +"~~~\n" +"# struct Point { x: f64, y: f64 }\n" +"let point = &@~Point { x: 10f, y: 20f };\n" +"println(fmt!(\"%f\", point.x));\n" +"~~~" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:119 +#: doc/guide-lifetimes.md:119 msgid "" "This declaration means that code can only pass `Point` by value to other " "functions. As a consequence, we had to explicitly take the address of " -"`on_the_stack` to get a borrowed pointer. Sometimes however it is more " -"convenient to move the & operator into the definition of `on_the_stack`:" +"`on_the_stack` to get a reference. Sometimes however it is more convenient " +"to move the & operator into the definition of `on_the_stack`:" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:124 +#: doc/guide-lifetimes.md:124 +#, fuzzy +#| msgid "" +#| "~~~ # struct Point { x: f64, y: f64 } let point = &@~Point { x: 10f, y: " +#| "20f }; println(fmt!(\"%f\", point.x)); ~~~" msgid "" -"~~~ # struct Point {x: float, y: float} let on_the_stack2: &Point = &Point " -"{x: 3.0, y: 4.0}; ~~~" +"~~~ # struct Point {x: f64, y: f64} let on_the_stack2: &Point = &Point {x: " +"3.0, y: 4.0}; ~~~" msgstr "" +"~~~\n" +"# struct Point { x: f64, y: f64 }\n" +"let point = &@~Point { x: 10f, y: 20f };\n" +"println(fmt!(\"%f\", point.x));\n" +"~~~" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:128 +#: doc/guide-lifetimes.md:128 msgid "" "Applying `&` to an rvalue (non-assignable location) is just a convenient " "shorthand for creating a temporary and taking its address. A more verbose " @@ -231,19 +327,28 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:134 +#: doc/guide-lifetimes.md:134 +#, fuzzy +#| msgid "" +#| "~~~ # struct Point { x: f64, y: f64 } let point = &@~Point { x: 10f, y: " +#| "20f }; println(fmt!(\"%f\", point.x)); ~~~" msgid "" -"~~~ # struct Point {x: float, y: float} let tmp = Point {x: 3.0, y: 4.0}; " -"let on_the_stack2 : &Point = &tmp; ~~~" +"~~~ # struct Point {x: f64, y: f64} let tmp = Point {x: 3.0, y: 4.0}; let " +"on_the_stack2 : &Point = &tmp; ~~~" msgstr "" +"~~~\n" +"# struct Point { x: f64, y: f64 }\n" +"let point = &@~Point { x: 10f, y: 20f };\n" +"println(fmt!(\"%f\", point.x));\n" +"~~~" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:136 +#: doc/guide-lifetimes.md:136 msgid "# Taking the address of fields" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:141 +#: doc/guide-lifetimes.md:141 msgid "" "As in C, the `&` operator is not limited to taking the address of local " "variables. It can also take the address of fields or individual array " @@ -251,78 +356,78 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:147 +#: doc/guide-lifetimes.md:147 msgid "" -"~~~ struct Point {x: float, y: float} // as before struct Size {w: float, h: " -"float} // as before struct Rectangle {origin: Point, size: Size} ~~~" +"~~~ struct Point {x: f64, y: f64} // as before struct Size {w: f64, h: " +"f64} // as before struct Rectangle {origin: Point, size: Size} ~~~" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:149 +#: doc/guide-lifetimes.md:149 msgid "Now, as before, we can define rectangles in a few different ways:" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:161 +#: doc/guide-lifetimes.md:161 #, no-wrap msgid "" "~~~\n" -"# struct Point {x: float, y: float}\n" -"# struct Size {w: float, h: float} // as before\n" +"# struct Point {x: f64, y: f64}\n" +"# struct Size {w: f64, h: f64} // as before\n" "# struct Rectangle {origin: Point, size: Size}\n" -"let rect_stack = &Rectangle {origin: Point {x: 1f, y: 2f},\n" -" size: Size {w: 3f, h: 4f}};\n" -"let rect_managed = @Rectangle {origin: Point {x: 3f, y: 4f},\n" -" size: Size {w: 3f, h: 4f}};\n" -"let rect_owned = ~Rectangle {origin: Point {x: 5f, y: 6f},\n" -" size: Size {w: 3f, h: 4f}};\n" +"let rect_stack = &Rectangle {origin: Point {x: 1.0, y: 2.0},\n" +" size: Size {w: 3.0, h: 4.0}};\n" +"let rect_managed = @Rectangle {origin: Point {x: 3.0, y: 4.0},\n" +" size: Size {w: 3.0, h: 4.0}};\n" +"let rect_owned = ~Rectangle {origin: Point {x: 5.0, y: 6.0},\n" +" size: Size {w: 3.0, h: 4.0}};\n" "~~~\n" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:164 +#: doc/guide-lifetimes.md:164 msgid "" "In each case, we can extract out individual subcomponents with the `&` " "operator. For example, I could write:" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:175 +#: doc/guide-lifetimes.md:175 msgid "" -"~~~ # struct Point {x: float, y: float} // as before # struct Size {w: " -"float, h: float} // as before # struct Rectangle {origin: Point, size: Size} " -"# let rect_stack = &Rectangle {origin: Point {x: 1f, y: 2f}, size: Size {w: " -"3f, h: 4f}}; # let rect_managed = @Rectangle {origin: Point {x: 3f, y: 4f}, " -"size: Size {w: 3f, h: 4f}}; # let rect_owned = ~Rectangle {origin: Point {x: " -"5f, y: 6f}, size: Size {w: 3f, h: 4f}}; # fn compute_distance(p1: &Point, " -"p2: &Point) -> float { 0f } compute_distance(&rect_stack.origin, " +"~~~ # struct Point {x: f64, y: f64} // as before # struct Size {w: f64, h: " +"f64} // as before # struct Rectangle {origin: Point, size: Size} # let " +"rect_stack = &Rectangle {origin: Point {x: 1.0, y: 2.0}, size: Size {w: 3.0, " +"h: 4.0}}; # let rect_managed = @Rectangle {origin: Point {x: 3.0, y: 4.0}, " +"size: Size {w: 3.0, h: 4.0}}; # let rect_owned = ~Rectangle {origin: Point " +"{x: 5.0, y: 6.0}, size: Size {w: 3.0, h: 4.0}}; # fn compute_distance(p1: " +"&Point, p2: &Point) -> f64 { 0.0 } compute_distance(&rect_stack.origin, " "&rect_managed.origin); ~~~" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:178 +#: doc/guide-lifetimes.md:178 msgid "" "which would borrow the field `origin` from the rectangle on the stack as " "well as from the managed box, and then compute the distance between them." msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:180 +#: doc/guide-lifetimes.md:180 msgid "# Borrowing managed boxes and rooting" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:186 +#: doc/guide-lifetimes.md:186 msgid "" "We’ve seen a few examples so far of borrowing heap boxes, both managed and " "owned. Up till this point, we’ve glossed over issues of safety. As stated in " -"the introduction, at runtime a borrowed pointer is simply a pointer, nothing " -"more. Therefore, avoiding C's problems with dangling pointers requires a " -"compile-time safety check." +"the introduction, at runtime a reference is simply a pointer, nothing more. " +"Therefore, avoiding C's problems with dangling pointers requires a compile-" +"time safety check." msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:197 +#: doc/guide-lifetimes.md:197 msgid "" "The basis for the check is the notion of _lifetimes_. A lifetime is a static " "approximation of the span of execution during which the pointer is valid: it " @@ -336,16 +441,16 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:202 +#: doc/guide-lifetimes.md:202 msgid "" -"When the `&` operator creates a borrowed pointer, the compiler must ensure " -"that the pointer remains valid for its entire lifetime. Sometimes this is " -"relatively easy, such as when taking the address of a local variable or a " -"field that is stored on the stack:" +"When the `&` operator creates a reference, the compiler must ensure that the " +"pointer remains valid for its entire lifetime. Sometimes this is relatively " +"easy, such as when taking the address of a local variable or a field that is " +"stored on the stack:" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:211 +#: doc/guide-lifetimes.md:211 #, no-wrap msgid "" "~~~\n" @@ -359,20 +464,20 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:216 +#: doc/guide-lifetimes.md:216 msgid "" -"Here, the lifetime of the borrowed pointer `y` is simply L, the remainder of " -"the function body. The compiler need not do any other work to prove that " -"code will not free `x.f`. This is true even if the code mutates `x`." +"Here, the lifetime of the reference `y` is simply L, the remainder of the " +"function body. The compiler need not do any other work to prove that code " +"will not free `x.f`. This is true even if the code mutates `x`." msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:218 +#: doc/guide-lifetimes.md:218 msgid "The situation gets more complex when borrowing data inside heap boxes:" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:227 +#: doc/guide-lifetimes.md:227 #, no-wrap msgid "" "~~~\n" @@ -386,7 +491,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:238 +#: doc/guide-lifetimes.md:238 msgid "" "In this example, the value `x` is a heap box, and `y` is therefore a pointer " "into that heap box. Again the lifetime of `y` is L, the remainder of the " @@ -400,14 +505,14 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:241 +#: doc/guide-lifetimes.md:241 msgid "" "> ***Note:*** Our current implementation implements the garbage collector > " "using reference counting and cycle detection." msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:247 +#: doc/guide-lifetimes.md:247 msgid "" "For this reason, whenever an `&` expression borrows the interior of a " "managed box stored in a mutable location, the compiler inserts a temporary " @@ -416,7 +521,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:257 +#: doc/guide-lifetimes.md:257 #, no-wrap msgid "" "~~~\n" @@ -431,19 +536,21 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:260 +#: doc/guide-lifetimes.md:260 msgid "" "Now if `x` is reassigned, the pointer `y` will still remain valid. This " "process is called *rooting*." msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:262 +#: doc/guide-lifetimes.md:262 +#, fuzzy +#| msgid "# Borrowed pointers" msgid "# Borrowing owned boxes" -msgstr "" +msgstr "# 借用ポインタ" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:268 +#: doc/guide-lifetimes.md:268 msgid "" "The previous example demonstrated *rooting*, the process by which the " "compiler ensures that managed boxes remain live for the duration of a " @@ -452,7 +559,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:274 +#: doc/guide-lifetimes.md:274 msgid "" "For owned boxes, therefore, the compiler will only allow a borrow *if the " "compiler can guarantee that the owned box will not be reassigned or moved " @@ -462,7 +569,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:289 +#: doc/guide-lifetimes.md:289 #, no-wrap msgid "" "~~~\n" @@ -482,7 +589,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:295 +#: doc/guide-lifetimes.md:295 msgid "" "Here, as before, the interior of the variable `x` is being borrowed and `x` " "is declared as mutable. However, the compiler can prove that `x` is not " @@ -492,7 +599,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:301 +#: doc/guide-lifetimes.md:301 msgid "" "It may not be clear why we are so concerned about mutating a borrowed " "variable. The reason is that the runtime system frees any owned box _as soon " @@ -501,7 +608,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:310 +#: doc/guide-lifetimes.md:310 #, no-wrap msgid "" "~~~ {.xfail-test}\n" @@ -515,14 +622,14 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:313 +#: doc/guide-lifetimes.md:313 msgid "" "To make this clearer, consider this diagram showing the state of memory " "immediately before the re-assignment of `x`:" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:316 doc/tutorial-borrowed-ptr.md:330 +#: doc/guide-lifetimes.md:316 doc/guide-lifetimes.md:330 #, no-wrap msgid "" "~~~ {.notrust}\n" @@ -530,7 +637,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:325 +#: doc/guide-lifetimes.md:325 #, no-wrap msgid "" " x +----------+\n" @@ -544,12 +651,12 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:327 +#: doc/guide-lifetimes.md:327 msgid "Once the reassignment occurs, the memory will look like this:" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:339 +#: doc/guide-lifetimes.md:339 #, no-wrap msgid "" " x +----------+ +---------+\n" @@ -563,14 +670,14 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:342 +#: doc/guide-lifetimes.md:342 msgid "" "Here you can see that the variable `y` still points at the old box, which " "has been freed." msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:348 +#: doc/guide-lifetimes.md:348 msgid "" "In fact, the compiler can apply the same kind of reasoning to any memory " "that is _(uniquely) owned by the stack frame_. So we could modify the " @@ -579,7 +686,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:353 +#: doc/guide-lifetimes.md:353 #, no-wrap msgid "" "~~~ {.xfail-test}\n" @@ -589,7 +696,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:361 +#: doc/guide-lifetimes.md:361 #, no-wrap msgid "" " let mut x = ~S {f: ~R {g: 3}};\n" @@ -602,7 +709,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:365 +#: doc/guide-lifetimes.md:365 msgid "" "In this case, two errors are reported, one when the variable `x` is modified " "and another when `x.f` is modified. Either modification would invalidate the " @@ -610,12 +717,14 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:367 +#: doc/guide-lifetimes.md:367 +#, fuzzy +#| msgid "# Borrowed pointers" msgid "# Borrowing and enums" -msgstr "" +msgstr "# 借用ポインタ" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:373 +#: doc/guide-lifetimes.md:373 msgid "" "The previous example showed that the type system forbids any borrowing of " "owned boxes found in aliasable, mutable memory. This restriction prevents " @@ -625,46 +734,46 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:376 +#: doc/guide-lifetimes.md:376 msgid "" "As an example, let’s look at the following `shape` type that can represent " "both rectangles and circles:" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:385 +#: doc/guide-lifetimes.md:385 #, no-wrap msgid "" "~~~\n" -"struct Point {x: float, y: float}; // as before\n" -"struct Size {w: float, h: float}; // as before\n" +"struct Point {x: f64, y: f64}; // as before\n" +"struct Size {w: f64, h: f64}; // as before\n" "enum Shape {\n" -" Circle(Point, float), // origin, radius\n" +" Circle(Point, f64), // origin, radius\n" " Rectangle(Point, Size) // upper-left, dimensions\n" "}\n" "~~~\n" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:389 +#: doc/guide-lifetimes.md:389 msgid "" "Now we might write a function to compute the area of a shape. This function " -"takes a borrowed pointer to a shape, to avoid the need for copying." +"takes a reference to a shape, to avoid the need for copying." msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:405 +#: doc/guide-lifetimes.md:405 #, no-wrap msgid "" "~~~\n" -"# struct Point {x: float, y: float}; // as before\n" -"# struct Size {w: float, h: float}; // as before\n" +"# struct Point {x: f64, y: f64}; // as before\n" +"# struct Size {w: f64, h: f64}; // as before\n" "# enum Shape {\n" -"# Circle(Point, float), // origin, radius\n" +"# Circle(Point, f64), // origin, radius\n" "# Rectangle(Point, Size) // upper-left, dimensions\n" "# }\n" -"# static tau: float = 6.28f;\n" -"fn compute_area(shape: &Shape) -> float {\n" +"# static tau: f64 = 6.28;\n" +"fn compute_area(shape: &Shape) -> f64 {\n" " match *shape {\n" " Circle(_, radius) => 0.5 * tau * radius * radius,\n" " Rectangle(_, ref size) => size.w * size.h\n" @@ -674,7 +783,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:410 +#: doc/guide-lifetimes.md:410 msgid "" "The first case matches against circles. Here, the pattern extracts the " "radius from the shape variant and the action uses it to compute the area of " @@ -683,12 +792,12 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:412 +#: doc/guide-lifetimes.md:412 msgid "[tau]: http://www.math.utah.edu/~palais/pi.html" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:418 +#: doc/guide-lifetimes.md:418 msgid "" "The second match is more interesting. Here we match against a rectangle and " "extract its size: but rather than copy the `size` struct, we use a by-" @@ -698,14 +807,14 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:421 +#: doc/guide-lifetimes.md:421 msgid "" "To make this more clear, let's look at a diagram of memory layout in the " "case where `shape` points at a rectangle:" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:424 doc/tutorial-borrowed-ptr.md:449 +#: doc/guide-lifetimes.md:424 doc/guide-lifetimes.md:449 #, no-wrap msgid "" "~~~ {.notrust}\n" @@ -713,21 +822,21 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:433 +#: doc/guide-lifetimes.md:433 #, no-wrap msgid "" "+-------+ +---------------+\n" "| shape | ------> | rectangle( |\n" -"+-------+ | {x: float, |\n" -"| size | -+ | y: float}, |\n" -"+-------+ +----> | {w: float, |\n" -" | h: float}) |\n" +"+-------+ | {x: f64, |\n" +"| size | -+ | y: f64}, |\n" +"+-------+ +----> | {w: f64, |\n" +" | h: f64}) |\n" " +---------------+\n" "~~~\n" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:440 +#: doc/guide-lifetimes.md:440 msgid "" "Here you can see that rectangular shapes are composed of five words of " "memory. The first is a tag indicating which variant this enum is " @@ -737,7 +846,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:446 +#: doc/guide-lifetimes.md:446 msgid "" "Perhaps you can see where the danger lies: if the shape were somehow to be " "reassigned, perhaps to a circle, then although the memory used to store that " @@ -747,75 +856,75 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:458 +#: doc/guide-lifetimes.md:458 #, no-wrap msgid "" "+-------+ +---------------+\n" "| shape | ------> | circle( |\n" -"+-------+ | {x: float, |\n" -"| size | -+ | y: float}, |\n" -"+-------+ +----> | float) |\n" +"+-------+ | {x: f64, |\n" +"| size | -+ | y: f64}, |\n" +"+-------+ +----> | f64) |\n" " | |\n" " +---------------+\n" "~~~\n" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:463 +#: doc/guide-lifetimes.md:463 msgid "" -"As you can see, the `size` pointer would be pointing at a `float` instead of " -"a struct. This is not good: dereferencing the second field of a `float` as " -"if it were a struct with two fields would be a memory safety violation." +"As you can see, the `size` pointer would be pointing at a `f64` instead of a " +"struct. This is not good: dereferencing the second field of a `f64` as if it " +"were a struct with two fields would be a memory safety violation." msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:475 +#: doc/guide-lifetimes.md:475 msgid "" "So, in fact, for every `ref` binding, the compiler will impose the same " "rules as the ones we saw for borrowing the interior of a owned box: it must " "be able to guarantee that the `enum` will not be overwritten for the " "duration of the borrow. In fact, the compiler would accept the example we " "gave earlier. The example is safe because the shape pointer has type " -"`&Shape`, which means \"borrowed pointer to immutable memory containing a " -"`shape`\". If, however, the type of that pointer were `&mut Shape`, then the " -"ref binding would be ill-typed. Just as with owned boxes, the compiler will " +"`&Shape`, which means \"reference to immutable memory containing a `shape`" +"\". If, however, the type of that pointer were `&mut Shape`, then the ref " +"binding would be ill-typed. Just as with owned boxes, the compiler will " "permit `ref` bindings into data owned by the stack frame even if the data " "are mutable, but otherwise it requires that the data reside in immutable " "memory." msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:477 -msgid "# Returning borrowed pointers" +#: doc/guide-lifetimes.md:477 +msgid "# Returning references" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:483 +#: doc/guide-lifetimes.md:483 msgid "" -"So far, all of the examples we have looked at, use borrowed pointers in a " -"“downward” direction. That is, a method or code block creates a borrowed " -"pointer, then uses it within the same scope. It is also possible to return " -"borrowed pointers as the result of a function, but as we'll see, doing so " -"requires some explicit annotation." +"So far, all of the examples we have looked at, use references in a " +"“downward” direction. That is, a method or code block creates a reference, " +"then uses it within the same scope. It is also possible to return references " +"as the result of a function, but as we'll see, doing so requires some " +"explicit annotation." msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:485 +#: doc/guide-lifetimes.md:485 msgid "For example, we could write a subroutine like this:" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:490 +#: doc/guide-lifetimes.md:490 msgid "" -"~~~ struct Point {x: float, y: float} fn get_x<'r>(p: &'r Point) -> &'r " -"float { &p.x } ~~~" +"~~~ struct Point {x: f64, y: f64} fn get_x<'r>(p: &'r Point) -> &'r f64 { &p." +"x } ~~~" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:498 +#: doc/guide-lifetimes.md:498 msgid "" "Here, the function `get_x()` returns a pointer into the structure it was " -"given. The type of the parameter (`&'r Point`) and return type (`&'r float`) " +"given. The type of the parameter (`&'r Point`) and return type (`&'r f64`) " "both use a new syntactic form that we have not seen so far. Here the " "identifier `r` names the lifetime of the pointer explicitly. So in effect, " "this function declares that it takes a pointer with lifetime `r` and returns " @@ -823,16 +932,16 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:504 +#: doc/guide-lifetimes.md:504 msgid "" -"In general, it is only possible to return borrowed pointers if they are " -"derived from a parameter to the procedure. In that case, the pointer result " -"will always have the same lifetime as one of the parameters; named lifetimes " +"In general, it is only possible to return references if they are derived " +"from a parameter to the procedure. In that case, the pointer result will " +"always have the same lifetime as one of the parameters; named lifetimes " "indicate which parameter that is." msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:510 +#: doc/guide-lifetimes.md:510 msgid "" "In the previous examples, function parameter types did not include a " "lifetime name. In those examples, the compiler simply creates a fresh name " @@ -841,7 +950,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:518 +#: doc/guide-lifetimes.md:518 msgid "" "Named lifetimes that appear in function signatures are conceptually the same " "as the other lifetimes we have seen before, but they are a bit abstract: " @@ -852,7 +961,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:523 +#: doc/guide-lifetimes.md:523 msgid "" "In any case, whatever the lifetime of `r` is, the pointer produced by `&p.x` " "always has the same lifetime as `p` itself: a pointer to a field of a struct " @@ -861,38 +970,37 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:526 +#: doc/guide-lifetimes.md:526 msgid "" "To emphasize this point, let’s look at a variation on the example, this time " "one that does not compile:" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:533 +#: doc/guide-lifetimes.md:533 #, no-wrap msgid "" "~~~ {.xfail-test}\n" -"struct Point {x: float, y: float}\n" -"fn get_x_sh(p: @Point) -> &float {\n" +"struct Point {x: f64, y: f64}\n" +"fn get_x_sh(p: @Point) -> &f64 {\n" " &p.x // Error reported here\n" "}\n" "~~~\n" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:541 +#: doc/guide-lifetimes.md:541 msgid "" "Here, the function `get_x_sh()` takes a managed box as input and returns a " -"borrowed pointer. As before, the lifetime of the borrowed pointer that will " -"be returned is a parameter (specified by the caller). That means that " -"`get_x_sh()` promises to return a borrowed pointer that is valid for as long " -"as the caller would like: this is subtly different from the first example, " -"which promised to return a pointer that was valid for as long as its pointer " -"argument was valid." +"reference. As before, the lifetime of the reference that will be returned is " +"a parameter (specified by the caller). That means that `get_x_sh()` promises " +"to return a reference that is valid for as long as the caller would like: " +"this is subtly different from the first example, which promised to return a " +"pointer that was valid for as long as its pointer argument was valid." msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:552 +#: doc/guide-lifetimes.md:552 msgid "" "Within `get_x_sh()`, we see the expression `&p.x` which takes the address of " "a field of a managed box. The presence of this expression implies that the " @@ -906,40 +1014,40 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:559 +#: doc/guide-lifetimes.md:559 msgid "" -"In general, if you borrow a managed (or owned) box to create a borrowed " -"pointer, the pointer will only be valid within the function and cannot be " -"returned. This is why the typical way to return borrowed pointers is to take " -"borrowed pointers as input (the only other case in which it can be legal to " -"return a borrowed pointer is if the pointer points at a static constant)." +"In general, if you borrow a managed (or owned) box to create a reference, it " +"will only be valid within the function and cannot be returned. This is why " +"the typical way to return references is to take references as input (the " +"only other case in which it can be legal to return a reference is if it " +"points at a static constant)." msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:561 +#: doc/guide-lifetimes.md:561 msgid "# Named lifetimes" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:565 +#: doc/guide-lifetimes.md:565 msgid "" "Let's look at named lifetimes in more detail. Named lifetimes allow for " "grouping of parameters by lifetime. For example, consider this function:" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:579 +#: doc/guide-lifetimes.md:579 #, no-wrap msgid "" "~~~\n" -"# struct Point {x: float, y: float}; // as before\n" -"# struct Size {w: float, h: float}; // as before\n" +"# struct Point {x: f64, y: f64}; // as before\n" +"# struct Size {w: f64, h: f64}; // as before\n" "# enum Shape {\n" -"# Circle(Point, float), // origin, radius\n" +"# Circle(Point, f64), // origin, radius\n" "# Rectangle(Point, Size) // upper-left, dimensions\n" "# }\n" -"# fn compute_area(shape: &Shape) -> float { 0f }\n" -"fn select<'r, T>(shape: &'r Shape, threshold: float,\n" +"# fn compute_area(shape: &Shape) -> f64 { 0.0 }\n" +"fn select<'r, T>(shape: &'r Shape, threshold: f64,\n" " a: &'r T, b: &'r T) -> &'r T {\n" " if compute_area(shape) > threshold {a} else {b}\n" "}\n" @@ -947,33 +1055,33 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:585 +#: doc/guide-lifetimes.md:585 msgid "" -"This function takes three borrowed pointers and assigns each the same " -"lifetime `r`. In practice, this means that, in the caller, the lifetime `r` " -"will be the *intersection of the lifetime of the three region parameters*. " -"This may be overly conservative, as in this example:" +"This function takes three references and assigns each the same lifetime " +"`r`. In practice, this means that, in the caller, the lifetime `r` will be " +"the *intersection of the lifetime of the three region parameters*. This may " +"be overly conservative, as in this example:" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:607 +#: doc/guide-lifetimes.md:607 #, no-wrap msgid "" "~~~\n" -"# struct Point {x: float, y: float}; // as before\n" -"# struct Size {w: float, h: float}; // as before\n" +"# struct Point {x: f64, y: f64}; // as before\n" +"# struct Size {w: f64, h: f64}; // as before\n" "# enum Shape {\n" -"# Circle(Point, float), // origin, radius\n" +"# Circle(Point, f64), // origin, radius\n" "# Rectangle(Point, Size) // upper-left, dimensions\n" "# }\n" -"# fn compute_area(shape: &Shape) -> float { 0f }\n" -"# fn select<'r, T>(shape: &Shape, threshold: float,\n" +"# fn compute_area(shape: &Shape) -> f64 { 0.0 }\n" +"# fn select<'r, T>(shape: &Shape, threshold: f64,\n" "# a: &'r T, b: &'r T) -> &'r T {\n" "# if compute_area(shape) > threshold {a} else {b}\n" "# }\n" " // -+ r\n" "fn select_based_on_unit_circle<'r, T>( // |-+ B\n" -" threshold: float, a: &'r T, b: &'r T) -> &'r T { // | |\n" +" threshold: f64, a: &'r T, b: &'r T) -> &'r T { // | |\n" " // | |\n" " let shape = Circle(Point {x: 0., y: 0.}, 1.); // | |\n" " select(&shape, threshold, a, b) // | |\n" @@ -983,7 +1091,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:617 +#: doc/guide-lifetimes.md:617 msgid "" "In this call to `select()`, the lifetime of the first parameter shape is B, " "the function body. Both of the second two parameters `a` and `b` share the " @@ -996,7 +1104,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:622 +#: doc/guide-lifetimes.md:622 msgid "" "To address this, we can modify the definition of `select()` to distinguish " "the lifetime of the first parameter from the lifetime of the latter two. " @@ -1005,18 +1113,18 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:636 +#: doc/guide-lifetimes.md:636 #, no-wrap msgid "" "~~~\n" -"# struct Point {x: float, y: float}; // as before\n" -"# struct Size {w: float, h: float}; // as before\n" +"# struct Point {x: f64, y: f64}; // as before\n" +"# struct Size {w: f64, h: f64}; // as before\n" "# enum Shape {\n" -"# Circle(Point, float), // origin, radius\n" +"# Circle(Point, f64), // origin, radius\n" "# Rectangle(Point, Size) // upper-left, dimensions\n" "# }\n" -"# fn compute_area(shape: &Shape) -> float { 0f }\n" -"fn select<'r, 'tmp, T>(shape: &'tmp Shape, threshold: float,\n" +"# fn compute_area(shape: &Shape) -> f64 { 0.0 }\n" +"fn select<'r, 'tmp, T>(shape: &'tmp Shape, threshold: f64,\n" " a: &'r T, b: &'r T) -> &'r T {\n" " if compute_area(shape) > threshold {a} else {b}\n" "}\n" @@ -1024,7 +1132,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:641 +#: doc/guide-lifetimes.md:641 msgid "" "Here you can see that `shape`'s lifetime is now named `tmp`. The parameters " "`a`, `b`, and the return value all have the lifetime `r`. However, since " @@ -1033,18 +1141,18 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:655 +#: doc/guide-lifetimes.md:655 #, no-wrap msgid "" "~~~\n" -"# struct Point {x: float, y: float}; // as before\n" -"# struct Size {w: float, h: float}; // as before\n" +"# struct Point {x: f64, y: f64}; // as before\n" +"# struct Size {w: f64, h: f64}; // as before\n" "# enum Shape {\n" -"# Circle(Point, float), // origin, radius\n" +"# Circle(Point, f64), // origin, radius\n" "# Rectangle(Point, Size) // upper-left, dimensions\n" "# }\n" -"# fn compute_area(shape: &Shape) -> float { 0f }\n" -"fn select<'r, T>(shape: &Shape, threshold: float,\n" +"# fn compute_area(shape: &Shape) -> f64 { 0.0 }\n" +"fn select<'r, T>(shape: &Shape, threshold: f64,\n" " a: &'r T, b: &'r T) -> &'r T {\n" " if compute_area(shape) > threshold {a} else {b}\n" "}\n" @@ -1052,20 +1160,21 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:657 +#: doc/guide-lifetimes.md:657 msgid "This is equivalent to the previous definition." msgstr "" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:659 +#: doc/guide-lifetimes.md:659 +#, fuzzy +#| msgid "## Conventions" msgid "# Conclusion" -msgstr "" +msgstr "## 本書の表記について" #. type: Plain text -#: doc/tutorial-borrowed-ptr.md:663 +#: doc/guide-lifetimes.md:663 msgid "" -"So there you have it: a (relatively) brief tour of the borrowed pointer " -"system. For more details, we refer to the (yet to be written) reference " -"document on borrowed pointers, which will explain the full notation and give " -"more examples." +"So there you have it: a (relatively) brief tour of the lifetime system. For " +"more details, we refer to the (yet to be written) reference document on " +"references, which will explain the full notation and give more examples." msgstr "" diff --git a/doc/po/ja/tutorial-macros.md.po b/doc/po/ja/guide-macros.md.po similarity index 86% rename from doc/po/ja/tutorial-macros.md.po rename to doc/po/ja/guide-macros.md.po index a7704bc94c1d2..e7ff87175ff99 100644 --- a/doc/po/ja/tutorial-macros.md.po +++ b/doc/po/ja/guide-macros.md.po @@ -1,13 +1,13 @@ # Japanese translations for Rust package -# Copyright (C) 2013 The Rust Project Developers +# Copyright (C) 2014 The Rust Project Developers # This file is distributed under the same license as the Rust package. -# Automatically generated, 2013. +# Automatically generated, 2014. # msgid "" msgstr "" -"Project-Id-Version: Rust 0.8\n" -"POT-Creation-Date: 2013-07-28 20:32+0900\n" -"PO-Revision-Date: 2013-07-28 20:32+0900\n" +"Project-Id-Version: Rust 0.9\n" +"POT-Creation-Date: 2014-01-10 12:20+0900\n" +"PO-Revision-Date: 2014-01-10 12:20+0900\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" "Language: ja\n" @@ -17,24 +17,19 @@ msgstr "" "Plural-Forms: nplurals=1; plural=0;\n" #. type: Plain text +#: doc/guide-conditions.md:4 doc/guide-ffi.md:4 doc/guide-lifetimes.md:4 +#: doc/guide-macros.md:4 doc/guide-rustpkg.md:4 doc/guide-tasks.md:4 #: doc/rust.md:4 doc/rustpkg.md:4 doc/tutorial.md:4 -#: doc/tutorial-borrowed-ptr.md:4 doc/tutorial-ffi.md:4 -#: doc/tutorial-macros.md:4 doc/tutorial-tasks.md:4 msgid "# Introduction" msgstr "# イントロダクション" #. type: Plain text -#: doc/rust.md:2136 doc/rust.md:2223 doc/tutorial-macros.md:323 -msgid "~~~~" -msgstr "" - -#. type: Plain text -#: doc/tutorial-macros.md:2 -msgid "% Rust Macros Tutorial" +#: doc/guide-macros.md:2 +msgid "% The Rust Macros Guide" msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:12 +#: doc/guide-macros.md:12 msgid "" "Functions are the primary tool that programmers can use to build " "abstractions. Sometimes, however, programmers want to abstract over compile-" @@ -45,7 +40,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:30 +#: doc/guide-macros.md:30 #, no-wrap msgid "" "~~~~\n" @@ -68,7 +63,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:38 +#: doc/guide-macros.md:38 msgid "" "This code could become tiresome if repeated many times. However, no " "function can capture its functionality to make it possible to abstract the " @@ -79,7 +74,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:59 +#: doc/guide-macros.md:59 #, no-wrap msgid "" "~~~~\n" @@ -105,7 +100,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:65 +#: doc/guide-macros.md:65 msgid "" "Macros are defined in pattern-matching style: in the above example, the text " "`($inp:expr $sp:ident)` that appears on the left-hand side of the `=>` is " @@ -115,12 +110,14 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:67 +#: doc/guide-macros.md:67 +#, fuzzy +#| msgid "## Do syntax" msgid "# Invocation syntax" -msgstr "" +msgstr "## do 構文" #. type: Plain text -#: doc/tutorial-macros.md:71 +#: doc/guide-macros.md:71 msgid "" "The macro invocation syntax specifies the syntax for the arguments to the " "macro. It appears on the left-hand side of the `=>` in a macro definition. " @@ -128,17 +125,17 @@ msgid "" msgstr "" #. type: Bullet: '1. ' -#: doc/tutorial-macros.md:76 +#: doc/guide-macros.md:76 msgid "It must be surrounded by parentheses." msgstr "" #. type: Bullet: '2. ' -#: doc/tutorial-macros.md:76 +#: doc/guide-macros.md:76 msgid "`$` has special meaning (described below)." msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:76 +#: doc/guide-macros.md:76 #, no-wrap msgid "" "3. The `()`s, `[]`s, and `{}`s it contains must balance. For example, `([)` is\n" @@ -146,12 +143,12 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:78 +#: doc/guide-macros.md:78 msgid "Otherwise, the invocation syntax is free-form." msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:83 +#: doc/guide-macros.md:83 #, no-wrap msgid "" "To take as an argument a fragment of Rust code, write `$` followed by a name\n" @@ -161,59 +158,61 @@ msgid "" msgstr "" #. type: Bullet: '* ' -#: doc/tutorial-macros.md:92 +#: doc/guide-macros.md:92 msgid "" "`ident` (an identifier, referring to a variable or item. Examples: `f`, `x`, " "`foo`.)" msgstr "" #. type: Bullet: '* ' -#: doc/tutorial-macros.md:92 +#: doc/guide-macros.md:92 msgid "" "`expr` (an expression. Examples: `2 + 2`; `if true then { 1 } else { 2 }`; " "`f(42)`.)" msgstr "" #. type: Bullet: '* ' -#: doc/tutorial-macros.md:92 +#: doc/guide-macros.md:92 msgid "`ty` (a type. Examples: `int`, `~[(char, ~str)]`, `&T`.)" msgstr "" #. type: Bullet: '* ' -#: doc/tutorial-macros.md:92 +#: doc/guide-macros.md:92 msgid "" "`pat` (a pattern, usually appearing in a `match` or on the left-hand side of " "a declaration. Examples: `Some(t)`; `(17, 'a')`; `_`.)" msgstr "" #. type: Bullet: '* ' -#: doc/tutorial-macros.md:92 +#: doc/guide-macros.md:92 msgid "" "`block` (a sequence of actions. Example: `{ log(error, \"hi\"); return 12; }" "`)" msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:95 +#: doc/guide-macros.md:95 msgid "" "The parser interprets any token that's not preceded by a `$` literally. " "Rust's usual rules of tokenization apply," msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:98 +#: doc/guide-macros.md:98 msgid "" "So `($x:ident -> (($e:expr)))`, though excessively fancy, would designate a " "macro that could be invoked like: `my_macro!(i->(( 2+2 )))`." msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:100 +#: doc/guide-macros.md:100 +#, fuzzy +#| msgid "# Introduction" msgid "## Invocation location" -msgstr "" +msgstr "# イントロダクション" #. type: Plain text -#: doc/tutorial-macros.md:105 +#: doc/guide-macros.md:105 msgid "" "A macro invocation may take the place of (and therefore expand to) an " "expression, an item, or a statement. The Rust parser will parse the macro " @@ -222,7 +221,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:112 +#: doc/guide-macros.md:112 msgid "" "At expansion time, the output of the macro will be parsed as whichever of " "the three nonterminals it stands in for. This means that a single macro " @@ -233,12 +232,12 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:115 +#: doc/guide-macros.md:115 msgid "# Transcription syntax" msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:119 +#: doc/guide-macros.md:119 msgid "" "The right-hand side of the `=>` follows the same rules as the left-hand " "side, except that a `$` need only be followed by the name of the syntactic " @@ -247,7 +246,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:126 +#: doc/guide-macros.md:126 msgid "" "The right-hand side must be enclosed by delimiters, which the transcriber " "ignores. Therefore `() => ((1,2,3))` is a macro that expands to a tuple " @@ -258,7 +257,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:133 +#: doc/guide-macros.md:133 msgid "" "Except for permissibility of `$name` (and `$(...)*`, discussed below), the " "right-hand side of a macro definition is ordinary Rust syntax. In " @@ -269,12 +268,14 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:135 +#: doc/guide-macros.md:135 +#, fuzzy +#| msgid "# Introduction" msgid "## Interpolation location" -msgstr "" +msgstr "# イントロダクション" #. type: Plain text -#: doc/tutorial-macros.md:139 +#: doc/guide-macros.md:139 msgid "" "The interpolation `$argument_name` may appear in any location consistent " "with its fragment specifier (i.e., if it is specified as `ident`, it may be " @@ -282,17 +283,19 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:141 +#: doc/guide-macros.md:141 msgid "# Multiplicity" msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:143 +#: doc/guide-macros.md:143 +#, fuzzy +#| msgid "# Introduction" msgid "## Invocation" -msgstr "" +msgstr "# イントロダクション" #. type: Plain text -#: doc/tutorial-macros.md:150 +#: doc/guide-macros.md:150 msgid "" "Going back to the motivating example, recall that `early_return` expanded " "into a `match` that would `return` if the `match`'s scrutinee matched the " @@ -303,7 +306,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:156 +#: doc/guide-macros.md:156 msgid "" "The syntax `$(...)*` on the left-hand side of the `=>` in a macro definition " "accepts zero or more occurrences of its contents. It works much like the `*` " @@ -313,7 +316,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:179 +#: doc/guide-macros.md:179 #, no-wrap msgid "" "~~~~\n" @@ -341,12 +344,14 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:181 +#: doc/guide-macros.md:181 +#, fuzzy +#| msgid "## Traits" msgid "### Transcription" -msgstr "" +msgstr "## トレイト" #. type: Plain text -#: doc/tutorial-macros.md:191 +#: doc/guide-macros.md:191 msgid "" "As the above example demonstrates, `$(...)*` is also valid on the right-hand " "side of a macro definition. The behavior of `*` in transcription, especially " @@ -360,19 +365,21 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:193 +#: doc/guide-macros.md:193 +#, fuzzy +#| msgid "## Pattern matching" msgid "## Parsing limitations" -msgstr "" +msgstr "## パターンマッチ" #. type: Plain text -#: doc/tutorial-macros.md:197 +#: doc/guide-macros.md:197 msgid "" "For technical reasons, there are two limitations to the treatment of syntax " "fragments by the macro parser:" msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:210 +#: doc/guide-macros.md:210 #, no-wrap msgid "" "1. The parser will always parse as much as possible of a Rust syntactic\n" @@ -390,27 +397,31 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:212 +#: doc/guide-macros.md:212 +#, fuzzy +#| msgid "## Pattern matching" msgid "# Macro argument pattern matching" -msgstr "" +msgstr "## パターンマッチ" #. type: Plain text -#: doc/tutorial-macros.md:214 -msgid "Now consider code like the following:" -msgstr "" +#: doc/guide-macros.md:214 +#, fuzzy +#| msgid "## Conventions" +msgid "## Motivation" +msgstr "## 本書の表記について" #. type: Plain text -#: doc/tutorial-macros.md:216 -msgid "## Motivation" +#: doc/guide-macros.md:216 +msgid "Now consider code like the following:" msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:236 +#: doc/guide-macros.md:236 #, no-wrap msgid "" "~~~~\n" "# enum t1 { good_1(t2, uint), bad_1 };\n" -"# pub struct t2 { body: t3 }\n" +"# struct t2 { body: t3 }\n" "# enum t3 { good_2(uint), bad_2};\n" "# fn f(x: t1) -> uint {\n" "match x {\n" @@ -430,7 +441,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:241 +#: doc/guide-macros.md:241 msgid "" "All the complicated stuff is deeply indented, and the error-handling code is " "separated from matches that fail. We'd like to write a macro that performs a " @@ -439,7 +450,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:263 +#: doc/guide-macros.md:263 #, no-wrap msgid "" "~~~~\n" @@ -466,11 +477,11 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:277 +#: doc/guide-macros.md:277 #, no-wrap msgid "" "# enum t1 { good_1(t2, uint), bad_1 };\n" -"# pub struct t2 { body: t3 }\n" +"# struct t2 { body: t3 }\n" "# enum t3 { good_2(uint), bad_2};\n" "# fn f(x: t1) -> uint {\n" "biased_match!((x) ~ (good_1(g1, val)) else { return 0 };\n" @@ -485,12 +496,17 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:288 +#: doc/guide-macros.md:281 +msgid "" +"This solves the indentation problem. But if we have a lot of chained matches " +"like this, we might prefer to write a single macro invocation. The input " +"pattern we want is clear:" +msgstr "" + +#. type: Plain text +#: doc/guide-macros.md:289 #, no-wrap msgid "" -"This solves the indentation problem. But if we have a lot of chained matches\n" -"like this, we might prefer to write a single macro invocation. The input\n" -"pattern we want is clear:\n" "~~~~\n" "# macro_rules! b(\n" " ( $( ($e:expr) ~ ($p:pat) else $err:stmt ; )*\n" @@ -501,19 +517,19 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:291 +#: doc/guide-macros.md:292 msgid "" "However, it's not possible to directly expand to nested match statements. " "But there is a solution." msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:293 +#: doc/guide-macros.md:294 msgid "## The recursive approach to macro writing" msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:297 +#: doc/guide-macros.md:298 msgid "" "A macro may accept multiple different input grammars. The first one to " "successfully match the actual argument to a macro invocation is the one that " @@ -521,7 +537,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:301 +#: doc/guide-macros.md:302 msgid "" "In the case of the example above, we want to write a recursive macro to " "process the semicolon-terminated lines, one-by-one. So, we want the " @@ -529,7 +545,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:308 +#: doc/guide-macros.md:308 #, no-wrap msgid "" "~~~~\n" @@ -537,11 +553,15 @@ msgid "" " ( binds $( $bind_res:ident ),* )\n" "# => (0))\n" "~~~~\n" -"...and:\n" msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:317 +#: doc/guide-macros.md:310 +msgid "...and:" +msgstr "" + +#. type: Plain text +#: doc/guide-macros.md:319 #, no-wrap msgid "" "~~~~\n" @@ -555,7 +575,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:321 +#: doc/guide-macros.md:323 msgid "" "The resulting macro looks like this. Note that the separation into " "`biased_match!` and `biased_match_rec!` occurs only because we have an outer " @@ -563,7 +583,12 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:342 +#: doc/guide-macros.md:325 doc/rust.md:2567 +msgid "~~~~" +msgstr "" + +#. type: Plain text +#: doc/guide-macros.md:344 #, no-wrap msgid "" "macro_rules! biased_match_rec (\n" @@ -587,7 +612,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:364 +#: doc/guide-macros.md:366 #, no-wrap msgid "" "// Wrap the whole thing in a `let`.\n" @@ -614,11 +639,11 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:378 +#: doc/guide-macros.md:380 #, no-wrap msgid "" "# enum t1 { good_1(t2, uint), bad_1 };\n" -"# pub struct t2 { body: t3 }\n" +"# struct t2 { body: t3 }\n" "# enum t3 { good_2(uint), bad_2};\n" "# fn f(x: t1) -> uint {\n" "biased_match!(\n" @@ -632,7 +657,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:382 +#: doc/guide-macros.md:384 msgid "" "This technique applies to many cases where transcribing a result all at once " "is not possible. The resulting code resembles ordinary functional " @@ -641,7 +666,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:390 +#: doc/guide-macros.md:392 msgid "" "The first difference is important, but also easy to forget: the " "transcription (right-hand) side of a `macro_rules!` rule is literal syntax, " @@ -654,7 +679,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:398 +#: doc/guide-macros.md:400 msgid "" "The second, related, difference is that the evaluation order of macros feels " "\"backwards\" compared to ordinary programming. Given an invocation `m1!(m2!" @@ -666,12 +691,12 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:400 +#: doc/guide-macros.md:402 msgid "# A final note" msgstr "" #. type: Plain text -#: doc/tutorial-macros.md:407 +#: doc/guide-macros.md:409 msgid "" "Macros, as currently implemented, are not for the faint of heart. Even " "ordinary syntax errors can be more difficult to debug when they occur inside " diff --git a/doc/po/ja/guide-pointers.md.po b/doc/po/ja/guide-pointers.md.po new file mode 100644 index 0000000000000..0be4a20f062fb --- /dev/null +++ b/doc/po/ja/guide-pointers.md.po @@ -0,0 +1,926 @@ +# Japanese translations for Rust package +# Copyright (C) 2014 The Rust Project Developers +# This file is distributed under the same license as the Rust package. +# Automatically generated, 2014. +# +msgid "" +msgstr "" +"Project-Id-Version: Rust 0.9\n" +"POT-Creation-Date: 2014-01-10 12:20+0900\n" +"PO-Revision-Date: 2014-01-10 12:20+0900\n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: ja\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=1; plural=0;\n" + +#. type: Plain text +#: doc/guide-pointers.md:2 +#, fuzzy +#| msgid "% The Rust Language Tutorial" +msgid "% The Rust Pointer Guide" +msgstr "% Rust 言語チュートリアル" + +#. type: Plain text +#: doc/guide-pointers.md:7 +msgid "" +"Rust's pointers are one of its more unique and compelling features. Pointers " +"are also one of the more confusing topics for newcomers to Rust. They can " +"also be confusing for people coming from other languages that support " +"pointers, such as C++. This guide will help you understand this important " +"topic." +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:9 +msgid "# You don't actually need pointers" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:15 +msgid "" +"I have good news for you: you probably don't need to care about pointers, " +"especially as you're getting started. Think of it this way: Rust is a " +"language that emphasizes safety. Pointers, as the joke goes, are very " +"pointy: it's easy to accidentally stab yourself. Therefore, Rust is made in " +"a way such that you don't need them very often." +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:17 +msgid "" +"\"But guide!\" you may cry. \"My co-worker wrote a function that looks like " +"this:" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:21 +#, fuzzy +#| msgid "~~~~ let square = |x: int| -> uint { (x * x) as uint }; ~~~~" +msgid "~~~rust fn succ(x: &int) -> int { *x + 1 } ~~~" +msgstr "" +"~~~~\n" +"let square = |x: int| -> uint { (x * x) as uint };\n" +"~~~~~~~~\n" + +#. type: Plain text +#: doc/guide-pointers.md:23 +msgid "So I wrote this code to try it out:" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:31 +#, no-wrap +msgid "" +"~~~rust{.xfail-test}\n" +"fn main() {\n" +" let number = 5;\n" +" let succ_number = succ(number);\n" +" println!(\"{}\", succ_number);\n" +"}\n" +"~~~\n" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:33 +msgid "And now I get an error:" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:37 +msgid "" +"~~~ {.notrust} error: mismatched types: expected `&int` but found `` " +"(expected &-ptr but found integral variable) ~~~" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:39 +msgid "What gives? It needs a pointer! Therefore I have to use pointers!\"" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:41 +msgid "" +"Turns out, you don't. All you need is a reference. Try this on for size:" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:50 +#, no-wrap +msgid "" +"~~~rust\n" +"# fn succ(x: &int) -> int { *x + 1 }\n" +"fn main() {\n" +" let number = 5;\n" +" let succ_number = succ(&number);\n" +" println!(\"{}\", succ_number);\n" +"}\n" +"~~~\n" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:52 +msgid "" +"It's that easy! One extra little `&` there. This code will run, and print " +"`6`." +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:55 +msgid "" +"That's all you need to know. Your co-worker could have written the function " +"like this:" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:58 +msgid "~~~rust fn succ(x: int) -> int { x + 1 }" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:65 +#, no-wrap +msgid "" +"fn main() {\n" +" let number = 5;\n" +" let succ_number = succ(number);\n" +" println!(\"{}\", succ_number);\n" +"}\n" +"~~~\n" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:70 +msgid "" +"No pointers even needed. Then again, this is a simple example. I assume that " +"your real-world `succ` function is more complicated, and maybe your co-" +"worker had a good reason for `x` to be a pointer of some kind. In that case, " +"references are your best friend. Don't worry about it, life is too short." +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:72 +msgid "However." +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:75 +msgid "" +"Here are the use-cases for pointers. I've prefixed them with the name of the " +"pointer that satisfies that use-case:" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:91 +#, no-wrap +msgid "" +"1. Owned: ~Trait must be a pointer, because you don't know the size of the\n" +"object, so indirection is mandatory.\n" +"2. Owned: You need a recursive data structure. These can be infinite sized, so\n" +"indirection is mandatory.\n" +"3. Owned: A very, very, very rare situation in which you have a *huge* chunk of\n" +"data that you wish to pass to many methods. Passing a pointer will make this\n" +"more efficient. If you're coming from another language where this technique is\n" +"common, such as C++, please read \"A note...\" below.\n" +"4. Managed: Having only a single owner to a piece of data would be inconvenient\n" +"or impossible. This is only often useful when a program is very large or very\n" +"complicated. Using a managed pointer will activate Rust's garbage collection\n" +"mechanism.\n" +"5. Reference: You're writing a function, and you need a pointer, but you don't\n" +"care about its ownership. If you make the argument a reference, callers\n" +"can send in whatever kind they want.\n" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:95 +msgid "" +"Five exceptions. That's it. Otherwise, you shouldn't need them. Be sceptical " +"of pointers in Rust: use them for a deliberate purpose, not just to make the " +"compiler happy." +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:97 +msgid "## A note for those proficient in pointers" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:102 +msgid "" +"If you're coming to Rust from a language like C or C++, you may be used to " +"passing things by reference, or passing things by pointer. In some " +"languages, like Java, you can't even have objects without a pointer to them. " +"Therefore, if you were writing this Rust code:" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:109 +#, no-wrap +msgid "" +"~~~rust\n" +"# fn transform(p: Point) -> Point { p }\n" +"struct Point {\n" +" x: int,\n" +" y: int,\n" +"}\n" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:115 +#, no-wrap +msgid "" +"fn main() {\n" +" let p0 = Point { x: 5, y: 10};\n" +" let p1 = transform(p0);\n" +" println!(\"{:?}\", p1);\n" +"}\n" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:117 doc/tutorial.md:2822 +msgid "~~~" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:119 +msgid "I think you'd implement `transform` like this:" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:129 +#, fuzzy, no-wrap +#| msgid "~~~~ {.xfail-test} # struct Point { x: f64, y: f64 } let mut mypoint = Point { x: 1.0, y: 1.0 }; let origin = Point { x: 0.0, y: 0.0 };" +msgid "" +"~~~rust\n" +"# struct Point {\n" +"# x: int,\n" +"# y: int,\n" +"# }\n" +"# let p0 = Point { x: 5, y: 10};\n" +"fn transform(p: &Point) -> Point {\n" +" Point { x: p.x + 1, y: p.y + 1}\n" +"}\n" +msgstr "" +"~~~~ {.xfail-test}\n" +"# struct Point { x: f64, y: f64 }\n" +"let mut mypoint = Point { x: 1.0, y: 1.0 };\n" +"let origin = Point { x: 0.0, y: 0.0 };" + +#. type: Plain text +#: doc/guide-pointers.md:133 +msgid "// and change this: let p1 = transform(&p0); ~~~" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:135 +msgid "" +"This does work, but you don't need to create those references! The better " +"way to write this is simply:" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:141 doc/guide-pointers.md:221 +#: doc/guide-pointers.md:238 doc/guide-pointers.md:296 +#, no-wrap +msgid "" +"~~~rust\n" +"struct Point {\n" +" x: int,\n" +" y: int,\n" +"}\n" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:145 +#, no-wrap +msgid "" +"fn transform(p: Point) -> Point {\n" +" Point { x: p.x + 1, y: p.y + 1}\n" +"}\n" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:152 +#, no-wrap +msgid "" +"fn main() {\n" +" let p0 = Point { x: 5, y: 10};\n" +" let p1 = transform(p0);\n" +" println!(\"{:?}\", p1);\n" +"}\n" +"~~~\n" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:160 +msgid "" +"But won't this be inefficient? Well, that's a complicated question, but it's " +"important to know that Rust, like C and C++, store aggregate data types " +"'unboxed,' whereas languages like Java and Ruby store these types as " +"'boxed.' For smaller structs, this way will be more efficient. For larger " +"ones, it may be less so. But don't reach for that pointer until you must! " +"Make sure that the struct is large enough by performing some tests before " +"you add in the complexity of pointers." +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:162 +#, fuzzy +#| msgid "# Borrowed pointers" +msgid "# Owned Pointers" +msgstr "# 借用ポインタ" + +#. type: Plain text +#: doc/guide-pointers.md:165 +msgid "" +"Owned pointers are the conceptually simplest kind of pointer in Rust. A " +"rough approximation of owned pointers follows:" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:171 +#, no-wrap +msgid "" +"1. Only one owned pointer may exist to a particular place in memory. It may be\n" +"borrowed from that owner, however.\n" +"2. The Rust compiler uses static analysis to determine where the pointer is in\n" +"scope, and handles allocating and de-allocating that memory. Owned pointers are\n" +"not garbage collected.\n" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:173 +msgid "These two properties make for three use cases." +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:175 +msgid "## References to Traits" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:179 +msgid "" +"Traits must be referenced through a pointer, because the struct that " +"implements the trait may be a different size than a different struct that " +"implements the trait. Therefore, unboxed traits don't make any sense, and " +"aren't allowed." +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:181 +#, fuzzy +#| msgid "# Data structures" +msgid "## Recursive Data Structures" +msgstr "# データ構造" + +#. type: Plain text +#: doc/guide-pointers.md:183 +msgid "" +"Sometimes, you need a recursive data structure. The simplest is known as a " +"'cons list':" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:189 +#, no-wrap +msgid "" +"~~~rust\n" +"enum List {\n" +" Nil,\n" +" Cons(T, ~List),\n" +"}\n" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:195 +#, no-wrap +msgid "" +"fn main() {\n" +" let list: List = Cons(1, ~Cons(2, ~Cons(3, ~Nil)));\n" +" println!(\"{:?}\", list);\n" +"}\n" +"~~~\n" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:197 +msgid "This prints:" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:201 +msgid "~~~ {.notrust} Cons(1, ~Cons(2, ~Cons(3, ~Nil))) ~~~" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:205 +msgid "" +"The inner lists _must_ be an owned pointer, because we can't know how many " +"elements are in the list. Without knowing the length, we don't know the " +"size, and therefore require the indirection that pointers offer." +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:207 +msgid "## Efficiency" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:213 +msgid "" +"This should almost never be a concern, but because creating an owned pointer " +"boxes its value, it therefore makes referring to the value the size of the " +"box. This may make passing an owned pointer to a function less expensive " +"than passing the value itself. Don't worry yourself with this case until " +"you've proved that it's an issue through benchmarks." +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:215 +msgid "For example, this will work:" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:229 +#, no-wrap +msgid "" +"fn main() {\n" +" let a = Point { x: 10, y: 20 };\n" +" do spawn {\n" +" println(a.x.to_str());\n" +" }\n" +"}\n" +"~~~\n" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:232 +msgid "" +"This struct is tiny, so it's fine. If `Point` were large, this would be more " +"efficient:" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:246 +#, no-wrap +msgid "" +"fn main() {\n" +" let a = ~Point { x: 10, y: 20 };\n" +" do spawn {\n" +" println(a.x.to_str());\n" +" }\n" +"}\n" +"~~~\n" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:249 +msgid "" +"Now it'll be copying a pointer-sized chunk of memory rather than the whole " +"struct." +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:251 +#, fuzzy +#| msgid "## Managed boxes" +msgid "# Managed Pointers" +msgstr "## マネージドボックス" + +#. type: Plain text +#: doc/guide-pointers.md:257 +msgid "" +"> **Note**: the `@` form of managed pointers is deprecated and behind a > " +"feature gate (it requires a `#[feature(managed_pointers)];` attribute on > " +"the crate root; remember the semicolon!). There are replacements, currently " +"> there is `std::rc::Rc` and `std::gc::Gc` for shared ownership via " +"reference > counting and garbage collection respectively." +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:261 +msgid "" +"Managed pointers, notated by an `@`, are used when having a single owner for " +"some data isn't convenient or possible. This generally happens when your " +"program is very large and complicated." +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:263 +msgid "" +"For example, let's say you're using an owned pointer, and you want to do " +"this:" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:269 +#, no-wrap +msgid "" +"~~~rust{.xfail-test}\n" +"struct Point {\n" +" x: int,\n" +" y: int,\n" +"}\n" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:277 +#, no-wrap +msgid "" +"fn main() {\n" +" let a = ~Point { x: 10, y: 20 };\n" +" let b = a;\n" +" println(b.x.to_str());\n" +" println(a.x.to_str());\n" +"}\n" +"~~~\n" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:279 +msgid "You'll get this error:" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:288 +#, no-wrap +msgid "" +"~~~ {.notrust}\n" +"test.rs:10:12: 10:13 error: use of moved value: `a`\n" +"test.rs:10 println(a.x.to_str());\n" +" ^\n" +"test.rs:8:8: 8:9 note: `a` moved here because it has type `~Point`, which is moved by default (use `ref` to override)\n" +"test.rs:8 let b = a;\n" +" ^\n" +"~~~\n" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:290 +msgid "" +"As the message says, owned pointers only allow for one owner at a time. When " +"you assign `a` to `b`, `a` becomes invalid. Change your code to this, " +"however:" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:304 +#, no-wrap +msgid "" +"fn main() {\n" +" let a = @Point { x: 10, y: 20 };\n" +" let b = a;\n" +" println(b.x.to_str());\n" +" println(a.x.to_str());\n" +"}\n" +"~~~\n" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:306 +msgid "And it works:" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:311 +msgid "~~~ {.notrust} 10 10 ~~~" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:314 +msgid "" +"So why not just use managed pointers everywhere? There are two big drawbacks " +"to managed pointers:" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:320 +#, no-wrap +msgid "" +"1. They activate Rust's garbage collector. Other pointer types don't share this\n" +"drawback.\n" +"2. You cannot pass this data to another task. Shared ownership across\n" +"concurrency boundaries is the source of endless pain in other languages, so\n" +"Rust does not let you do this.\n" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:322 doc/tutorial.md:1345 +#, fuzzy +#| msgid "# Dereferencing pointers" +msgid "# References" +msgstr "# ポインタのデリファレンス" + +#. type: Plain text +#: doc/guide-pointers.md:329 +msgid "" +"References are the third major kind of pointer Rust supports. They are " +"simultaneously the simplest and the most complicated kind. Let me explain: " +"references are considered 'borrowed' because they claim no ownership over " +"the data they're pointing to. They're just borrowing it for a while. So in " +"that sense, they're simple: just keep whatever ownership the data already " +"has. For example:" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:332 +#, fuzzy +#| msgid "~~~~ use std::task::spawn;" +msgid "~~~rust use std::num::sqrt;" +msgstr "" +"~~~~\n" +"use std::task::spawn;" + +#. type: Plain text +#: doc/guide-pointers.md:337 +#, no-wrap +msgid "" +"struct Point {\n" +" x: f32,\n" +" y: f32,\n" +"}\n" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:341 +#, no-wrap +msgid "" +"fn compute_distance(p1: &Point, p2: &Point) -> f32 {\n" +" let x_d = p1.x - p2.x;\n" +" let y_d = p1.y - p2.y;\n" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:344 +#, no-wrap +msgid "" +" sqrt(x_d * x_d + y_d * y_d)\n" +"}\n" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:348 +#, fuzzy, no-wrap +#| msgid "~~~~ {.xfail-test} # struct Point { x: f64, y: f64 } let mut mypoint = Point { x: 1.0, y: 1.0 }; let origin = Point { x: 0.0, y: 0.0 };" +msgid "" +"fn main() {\n" +" let origin = @Point { x: 0.0, y: 0.0 };\n" +" let p1 = ~Point { x: 5.0, y: 3.0 };\n" +msgstr "" +"~~~~ {.xfail-test}\n" +"# struct Point { x: f64, y: f64 }\n" +"let mut mypoint = Point { x: 1.0, y: 1.0 };\n" +"let origin = Point { x: 0.0, y: 0.0 };" + +#. type: Plain text +#: doc/guide-pointers.md:352 +#, no-wrap +msgid "" +" println!(\"{:?}\", compute_distance(origin, p1));\n" +"}\n" +"~~~\n" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:357 +msgid "" +"This prints `5.83095189`. You can see that the `compute_distance` function " +"takes in two references, but we give it a managed and unique pointer. Of " +"course, if this were a real program, we wouldn't have any of these pointers, " +"they're just there to demonstrate the concepts." +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:363 +msgid "" +"So how is this hard? Well, because we're ignoring ownership, the compiler " +"needs to take great care to make sure that everything is safe. Despite their " +"complete safety, a reference's representation at runtime is the same as that " +"of an ordinary pointer in a C program. They introduce zero overhead. The " +"compiler does all safety checks at compile time." +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:367 +msgid "" +"This theory is called 'region pointers,' and involve a concept called " +"'lifetimes'. Here's the simple explanation: would you expect this code to " +"compile?" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:374 +#, no-wrap +msgid "" +"~~~rust{.xfail-test}\n" +"fn main() {\n" +" println(x.to_str());\n" +" let x = 5;\n" +"}\n" +"~~~\n" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:379 +msgid "" +"Probably not. That's because you know that the name `x` is valid from where " +"it's declared to when it goes out of scope. In this case, that's the end of " +"the `main` function. So you know this code will cause an error. We call this " +"duration a 'lifetime'. Let's try a more complex example:" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:392 +#, no-wrap +msgid "" +"~~~rust\n" +"fn main() {\n" +" let mut x = ~5;\n" +" if *x < 10 {\n" +" let y = &x;\n" +" println!(\"Oh no: {:?}\", y);\n" +" return;\n" +" }\n" +" *x -= 1;\n" +" println!(\"Oh no: {:?}\", x);\n" +"}\n" +"~~~\n" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:396 +msgid "" +"Here, we're borrowing a pointer to `x` inside of the `if`. The compiler, " +"however, is able to determine that that pointer will go out of scope without " +"`x` being mutated, and therefore, lets us pass. This wouldn't work:" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:403 +#, no-wrap +msgid "" +"~~~rust{.xfail-test}\n" +"fn main() {\n" +" let mut x = ~5;\n" +" if *x < 10 {\n" +" let y = &x;\n" +" *x -= 1;\n" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:411 +#, no-wrap +msgid "" +" println!(\"Oh no: {:?}\", y);\n" +" return;\n" +" }\n" +" *x -= 1;\n" +" println!(\"Oh no: {:?}\", x);\n" +"}\n" +"~~~\n" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:413 +msgid "It gives this error:" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:422 +#, no-wrap +msgid "" +"~~~ {.notrust}\n" +"test.rs:5:8: 5:10 error: cannot assign to `*x` because it is borrowed\n" +"test.rs:5 *x -= 1;\n" +" ^~\n" +"test.rs:4:16: 4:18 note: borrow of `*x` occurs here\n" +"test.rs:4 let y = &x;\n" +" ^~\n" +"~~~\n" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:427 +msgid "" +"As you might guess, this kind of analysis is complex for a human, and " +"therefore hard for a computer, too! There is an entire [guide devoted to " +"references and lifetimes](guide-lifetimes.html) that goes into lifetimes in " +"great detail, so if you want the full details, check that out." +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:429 +#, fuzzy +#| msgid "# Dereferencing pointers" +msgid "# Returning Pointers" +msgstr "# ポインタのデリファレンス" + +#. type: Plain text +#: doc/guide-pointers.md:433 +msgid "" +"We've talked a lot about functions that accept various kinds of pointers, " +"but what about returning them? Here's the rule of thumb: only return a " +"unique or managed pointer if you were given one in the first place." +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:435 +msgid "What does that mean? Don't do this:" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:440 +#, no-wrap +msgid "" +"~~~rust\n" +"fn foo(x: ~int) -> ~int {\n" +" return ~*x;\n" +"}\n" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:446 +#, no-wrap +msgid "" +"fn main() {\n" +" let x = ~5;\n" +" let y = foo(x);\n" +"}\n" +"~~~\n" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:448 +msgid "Do this:" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:453 doc/guide-pointers.md:467 +#, no-wrap +msgid "" +"~~~rust\n" +"fn foo(x: ~int) -> int {\n" +" return *x;\n" +"}\n" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:459 +#, no-wrap +msgid "" +"fn main() {\n" +" let x = ~5;\n" +" let y = ~foo(x);\n" +"}\n" +"~~~\n" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:462 +msgid "" +"This gives you flexibility, without sacrificing performance. For example, " +"this will also work:" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:473 +#, no-wrap +msgid "" +"fn main() {\n" +" let x = ~5;\n" +" let y = @foo(x);\n" +"}\n" +"~~~\n" +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:480 +msgid "" +"You may think that this gives us terrible performance: return a value and " +"then immediately box it up?!?! Isn't that the worst of both worlds? Rust is " +"smarter than that. There is no copy in this code. `main` allocates enough " +"room for the `@int`, passes a pointer to that memory into `foo` as `x`, and " +"then `foo` writes the value straight into that pointer. This writes the " +"return value directly into the allocated box." +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:484 +msgid "" +"This is important enough that it bears repeating: pointers are not for " +"optimizing returning values from your code. Allow the caller to choose how " +"they want to use your output." +msgstr "" + +#. type: Plain text +#: doc/guide-pointers.md:487 +msgid "# Related Resources" +msgstr "" + +#. type: Bullet: '* ' +#: doc/guide-pointers.md:488 +msgid "[Lifetimes guide](guide-lifetimes.html)" +msgstr "" diff --git a/doc/po/ja/guide-rustpkg.md.po b/doc/po/ja/guide-rustpkg.md.po new file mode 100644 index 0000000000000..851e5d399536f --- /dev/null +++ b/doc/po/ja/guide-rustpkg.md.po @@ -0,0 +1,527 @@ +# Japanese translations for Rust package +# Copyright (C) 2014 The Rust Project Developers +# This file is distributed under the same license as the Rust package. +# Automatically generated, 2014. +# +msgid "" +msgstr "" +"Project-Id-Version: Rust 0.9\n" +"POT-Creation-Date: 2014-01-10 12:20+0900\n" +"PO-Revision-Date: 2014-01-10 12:20+0900\n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: ja\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=1; plural=0;\n" + +#. type: Plain text +#: doc/guide-conditions.md:4 doc/guide-ffi.md:4 doc/guide-lifetimes.md:4 +#: doc/guide-macros.md:4 doc/guide-rustpkg.md:4 doc/guide-tasks.md:4 +#: doc/rust.md:4 doc/rustpkg.md:4 doc/tutorial.md:4 +msgid "# Introduction" +msgstr "# イントロダクション" + +#. type: Plain text +#: doc/guide-rustpkg.md:2 +#, fuzzy +#| msgid "% The Rust Language Tutorial" +msgid "% The Rust Packaging Guide" +msgstr "% Rust 言語チュートリアル" + +#. type: Plain text +#: doc/guide-rustpkg.md:9 +msgid "" +"Sharing is caring. Rust comes with a tool, `rustpkg`, which allows you to " +"package up your Rust code and share it with other people. This guide will " +"get you started on all of the concepts and commands you need to give the " +"gift of Rust code to someone else." +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:11 +msgid "# Installing External Packages" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:14 +msgid "" +"First, let's try to use an external package somehow. I've made a sample " +"package called `hello` to demonstrate how to do so. Here's how `hello` is " +"used:" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:17 +msgid "~~~~ extern mod hello;" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:22 +#, no-wrap +msgid "" +"fn main() {\n" +" hello::world();\n" +"}\n" +"~~~~\n" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:24 +msgid "Easy! But if you try to compile this, you'll get an error:" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:31 +#, no-wrap +msgid "" +"~~~~ {.notrust}\n" +"$ rustc main.rs \n" +"main.rs:1:0: 1:17 error: can't find crate for `hello`\n" +"main.rs:1 extern mod hello;\n" +" ^~~~~~~~~~~~~~~~~\n" +"~~~~\n" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:35 +msgid "" +"This makes sense, as we haven't gotten it from anywhere yet! Luckily for us, " +"`rustpkg` has an easy way to fetch others' code: the `install` command. It's " +"used like this:" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:39 +msgid "~~~ {.notrust} $ rustpkg install PKG_ID ~~~" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:47 +msgid "" +"This will install a package named `PKG_ID` into your current Rust " +"environment. I called it `PKG_ID` in this example because `rustpkg` calls " +"this a 'package identifier.' When using it with an external package like " +"this, it's often a URI fragment. You see, Rust has no central authority for " +"packages. You can build your own `hello` library if you want, and that's " +"fine. We'd both host them in different places and different projects would " +"rely on whichever version they preferred." +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:49 +msgid "To install the `hello` library, simply run this in your terminal:" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:53 +msgid "~~~ {.notrust} $ rustpkg install github.com/steveklabnik/hello ~~~" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:55 +msgid "You should see a message that looks like this:" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:59 +msgid "" +"~~~ {.notrust} note: Installed package github.com/steveklabnik/hello-0.1 to /" +"some/path/.rust ~~~" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:61 +msgid "Now, compiling our example should work:" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:67 +msgid "~~~ {.notrust} $ rustc main.rs $ ./main Hello, world. ~~~" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:69 +msgid "Simple! That's all it takes." +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:71 +msgid "# Workspaces" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:76 +msgid "" +"Before we can talk about how to make packages of your own, you have to " +"understand the big concept with `rustpkg`: workspaces. A 'workspace' is " +"simply a directory that has certain sub-directories that `rustpkg` expects. " +"Different Rust projects will go into different workspaces." +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:79 +msgid "" +"A workspace consists of any directory that has the following directories:" +msgstr "" + +#. type: Bullet: '* ' +#: doc/guide-rustpkg.md:84 +msgid "`src`: The directory where all the source code goes." +msgstr "" + +#. type: Bullet: '* ' +#: doc/guide-rustpkg.md:84 +msgid "`build`: This directory contains all of the build output." +msgstr "" + +#. type: Bullet: '* ' +#: doc/guide-rustpkg.md:84 +msgid "" +"`lib`: The directory where any libraries distributed with the package go." +msgstr "" + +#. type: Bullet: '* ' +#: doc/guide-rustpkg.md:84 +msgid "`bin`: This directory holds any binaries distributed with the package." +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:86 +msgid "There are also default file names you'll want to follow as well:" +msgstr "" + +#. type: Bullet: '* ' +#: doc/guide-rustpkg.md:89 +msgid "`main.rs`: A file that's going to become an executable." +msgstr "" + +#. type: Bullet: '* ' +#: doc/guide-rustpkg.md:89 +msgid "`lib.rs`: A file that's going to become a library." +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:91 +msgid "# Building your own Package" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:96 +msgid "" +"Now that you've got workspaces down, let's build your own copy of `hello`. " +"Go to wherever you keep your personal projects, and let's make all of the " +"directories we'll need. I'll refer to this personal project directory as `~/" +"src` for the rest of this guide." +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:98 +msgid "## Creating our workspace" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:104 +msgid "~~~ {.notrust} $ cd ~/src $ mkdir -p hello/src/hello $ cd hello ~~~" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:106 +msgid "Easy enough! Let's do one or two more things that are nice to do:" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:111 +msgid "~~~ {.notrust} $ git init . $ cat > README.md # hello" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:113 +msgid "A simple package for Rust." +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:115 +#, fuzzy +#| msgid "# Introduction" +msgid "## Installation" +msgstr "# イントロダクション" + +#. type: Plain text +#: doc/guide-rustpkg.md:126 +msgid "" +"``` $ rustpkg install github.com/YOUR_USERNAME/hello ``` ^D $ cat > ." +"gitignore .rust build ^D $ git commit -am \"Initial commit.\" ~~~" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:129 +msgid "" +"If you're not familliar with the `cat >` idiom, it will make files with the " +"text you type inside. Control-D (`^D`) ends the text for the file." +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:138 +msgid "" +"Anyway, we've got a README and a `.gitignore`. Let's talk about that `." +"gitignore` for a minute: we are ignoring two directories, `build` and `." +"rust`. `build`, as we discussed earlier, is for build artifacts, and we " +"don't want to check those into a repository. `.rust` is a directory that " +"`rustpkg` uses to keep track of its own settings, as well as the source code " +"of any other external packages that this workspace uses. This is where that " +"`rustpkg install` puts all of its files. Those are also not to go into our " +"repository, so we ignore it all as well." +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:140 +msgid "Next, let's add a source file:" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:144 +msgid "~~~ #[desc = \"A hello world Rust package.\"]; #[license = \"MIT\"];" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:149 +#, no-wrap +msgid "" +"pub fn world() {\n" +" println(\"Hello, world.\");\n" +"}\n" +"~~~\n" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:151 +msgid "" +"Put this into `src/hello/lib.rs`. Let's talk about each of these attributes:" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:153 +msgid "## Crate attributes for packages" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:156 +msgid "" +"`license` is equally simple: the license we want this code to have. I chose " +"MIT here, but you should pick whatever license makes the most sense for you." +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:159 +msgid "" +"`desc` is a description of the package and what it does. This should just be " +"a sentence or two." +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:161 +msgid "## Building your package" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:163 +msgid "Building your package is simple:" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:167 +msgid "~~~ {.notrust} $ rustpkg build hello ~~~" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:170 +msgid "" +"This will compile `src/hello/lib.rs` into a library. After this process " +"completes, you'll want to check out `build`:" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:175 +msgid "" +"~~~ {.notrust} $ ls build/x86_64-unknown-linux-gnu/hello/ libhello-" +"ed8619dad9ce7d58-0.1.0.so ~~~" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:178 +msgid "" +"This directory naming structure is called a 'build triple,' and is because " +"I'm on 64 bit Linux. Yours may differ based on platform." +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:182 +msgid "" +"You'll also notice that `src/hello/lib.rs` turned into `libhello-" +"ed8619dad9ce7d58-0.1.0.so`. This is a simple combination of the library " +"name, a hash of its content, and the version." +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:184 +msgid "Now that your library builds, you'll want to commit:" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:189 +msgid "" +"~~~ {.notrust} $ git add src $ git commit -m \"Adding source code.\" ~~~" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:191 +msgid "If you're using GitHub, after creating the project, do this:" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:196 +msgid "" +"~~~ {.notrust} $ git remote add origin git@github.com:YOUR_USERNAME/hello." +"git $ git push origin -u master ~~~" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:198 +msgid "Now you can install and use it! Go anywhere else in your filesystem:" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:205 +msgid "" +"~~~ {.notrust} $ cd ~/src/foo $ rustpkg install github.com/YOUR_USERNAME/" +"hello WARNING: The Rust package manager is experimental and may be unstable " +"note: Installed package github.com/YOUR_USERNAME/hello-0.1 to /home/" +"yourusername/src/hello/.rust ~~~" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:207 +msgid "That's it!" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:209 +#, fuzzy +#| msgid "## Using other crates" +msgid "# Testing your Package" +msgstr "## 他のクレートの利用" + +#. type: Plain text +#: doc/guide-rustpkg.md:212 +msgid "" +"Testing your package is simple as well. First, let's change `src/hello/lib." +"rs` to contain a function that can be sensibly tested:" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:216 +msgid "" +"~~~ #[desc = \"A Rust package for determining whether unsigned integers are " +"even.\"]; #[license = \"MIT\"];" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:221 +#, no-wrap +msgid "" +"pub fn is_even(i: uint) -> bool {\n" +" i % 2 == 0\n" +"}\n" +"~~~\n" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:224 +msgid "" +"Once you've edited `lib.rs`, you can create a second crate file, `src/hello/" +"test.rs`, to put tests in:" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:229 +msgid "~~~ #[license = \"MIT\"]; extern mod hello; use hello::is_even;" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:237 +#, no-wrap +msgid "" +"#[test]\n" +"fn test_is_even() {\n" +" assert!(is_even(0));\n" +" assert!(!is_even(1));\n" +" assert!(is_even(2));\n" +"}\n" +"~~~\n" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:241 +msgid "" +"Note that you have to import the crate you just created in `lib.rs` with the " +"`extern mod hello` directive. That's because you're putting the tests in a " +"different crate from the main library that you created." +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:244 +msgid "" +"Now, you can use the `rustpkg test` command to build this test crate (and " +"anything else it depends on) and run the tests, all in one step:" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:249 +msgid "" +"~~~ {.notrust} $ rustpkg test hello WARNING: The Rust package manager is " +"experimental and may be unstable note: Installed package hello-0.1 to /Users/" +"tjc/.rust" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:252 +msgid "running 1 test test test_is_even ... ok" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:255 doc/guide-testing.md:28 +msgid "test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured ~~~" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:257 +msgid "# More resources" +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:261 +msgid "" +"There's a lot more going on with `rustpkg`, this is just to get you " +"started. Check out [the rustpkg manual](rustpkg.html) for the full details " +"on how to customize `rustpkg`." +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:267 +msgid "" +"A tag was created on GitHub specifically for `rustpkg`-related issues. You " +"can [see all the Issues for rustpkg here](https://github.com/mozilla/rust/" +"issues?direction=desc&labels=A-pkg&sort=created&state=open), with bugs as " +"well as new feature plans. `rustpkg` is still under development, and so may " +"be a bit flaky at the moment." +msgstr "" + +#. type: Plain text +#: doc/guide-rustpkg.md:270 +msgid "" +"You may also want to check out [this blog post](http://tim.dreamwidth." +"org/1820526.html), which contains some of the early design decisions and " +"justifications." +msgstr "" diff --git a/doc/po/ja/tutorial-tasks.md.po b/doc/po/ja/guide-tasks.md.po similarity index 61% rename from doc/po/ja/tutorial-tasks.md.po rename to doc/po/ja/guide-tasks.md.po index 2276d0052a643..8459849787935 100644 --- a/doc/po/ja/tutorial-tasks.md.po +++ b/doc/po/ja/guide-tasks.md.po @@ -1,13 +1,13 @@ # Japanese translations for Rust package -# Copyright (C) 2013 The Rust Project Developers +# Copyright (C) 2014 The Rust Project Developers # This file is distributed under the same license as the Rust package. -# Automatically generated, 2013. +# Automatically generated, 2014. # msgid "" msgstr "" -"Project-Id-Version: Rust 0.8\n" -"POT-Creation-Date: 2013-08-08 22:27+0900\n" -"PO-Revision-Date: 2013-07-28 20:32+0900\n" +"Project-Id-Version: Rust 0.9\n" +"POT-Creation-Date: 2014-01-10 12:20+0900\n" +"PO-Revision-Date: 2014-01-10 12:20+0900\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" "Language: ja\n" @@ -17,34 +17,31 @@ msgstr "" "Plural-Forms: nplurals=1; plural=0;\n" #. type: Plain text +#: doc/guide-conditions.md:4 doc/guide-ffi.md:4 doc/guide-lifetimes.md:4 +#: doc/guide-macros.md:4 doc/guide-rustpkg.md:4 doc/guide-tasks.md:4 #: doc/rust.md:4 doc/rustpkg.md:4 doc/tutorial.md:4 -#: doc/tutorial-borrowed-ptr.md:4 doc/tutorial-ffi.md:4 -#: doc/tutorial-macros.md:4 doc/tutorial-tasks.md:4 msgid "# Introduction" msgstr "# イントロダクション" #. type: Plain text -#: doc/rust.md:1952 doc/tutorial-tasks.md:648 -msgid "# } ~~~~" -msgstr "" - -#. type: Plain text -#: doc/tutorial-tasks.md:2 -msgid "% Rust Tasks and Communication Tutorial" -msgstr "" +#: doc/guide-tasks.md:2 +#, fuzzy +#| msgid "[Tasks and communication][tasks]" +msgid "% The Rust Tasks and Communication Guide" +msgstr "[タスクと通信][tasks]" #. type: Plain text -#: doc/tutorial-tasks.md:10 +#: doc/guide-tasks.md:10 msgid "" "Rust provides safe concurrency through a combination of lightweight, memory-" -"isolated tasks and message passing. This tutorial will describe the " +"isolated tasks and message passing. This guide will describe the " "concurrency model in Rust, how it relates to the Rust type system, and " "introduce the fundamental library abstractions for constructing concurrent " "programs." msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:19 +#: doc/guide-tasks.md:19 msgid "" "Rust tasks are not the same as traditional threads: rather, they are " "considered _green threads_, lightweight units of execution that the Rust " @@ -57,7 +54,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:26 +#: doc/guide-tasks.md:26 msgid "" "In order to make efficient use of memory Rust tasks have dynamically sized " "stacks. A task begins its life with a small amount of stack space " @@ -68,7 +65,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:32 +#: doc/guide-tasks.md:32 msgid "" "Tasks provide failure isolation and recovery. When a fatal error occurs in " "Rust code as a result of an explicit call to `fail!()`, an assertion " @@ -78,7 +75,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:37 +#: doc/guide-tasks.md:37 msgid "" "Tasks use Rust's type system to provide strong memory safety guarantees. In " "particular, the type system guarantees that tasks cannot share mutable state " @@ -87,12 +84,12 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:39 +#: doc/guide-tasks.md:39 msgid "## A note about the libraries" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:44 +#: doc/guide-tasks.md:44 msgid "" "While Rust's type system provides the building blocks needed for safe and " "efficient tasks, all of the task functionality itself is implemented in the " @@ -101,66 +98,64 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:47 +#: doc/guide-tasks.md:47 msgid "" "For your reference, these are the standard modules involved in Rust " "concurrency at this writing:" msgstr "" #. type: Bullet: '* ' -#: doc/tutorial-tasks.md:56 +#: doc/guide-tasks.md:55 msgid "[`std::task`] - All code relating to tasks and task scheduling," msgstr "" #. type: Bullet: '* ' -#: doc/tutorial-tasks.md:56 +#: doc/guide-tasks.md:55 msgid "[`std::comm`] - The message passing interface," msgstr "" #. type: Bullet: '* ' -#: doc/tutorial-tasks.md:56 -msgid "[`std::pipes`] - The underlying messaging infrastructure," +#: doc/guide-tasks.md:55 +msgid "[`extra::comm`] - Additional messaging types based on `std::comm`," msgstr "" #. type: Bullet: '* ' -#: doc/tutorial-tasks.md:56 -msgid "[`extra::comm`] - Additional messaging types based on `std::pipes`," -msgstr "" - -#. type: Bullet: '* ' -#: doc/tutorial-tasks.md:56 +#: doc/guide-tasks.md:55 msgid "[`extra::sync`] - More exotic synchronization tools, including locks," msgstr "" #. type: Bullet: '* ' -#: doc/tutorial-tasks.md:56 +#: doc/guide-tasks.md:55 msgid "" "[`extra::arc`] - The Arc (atomically reference counted) type, for safely " "sharing immutable data," msgstr "" #. type: Bullet: '* ' -#: doc/tutorial-tasks.md:56 +#: doc/guide-tasks.md:55 msgid "" "[`extra::future`] - A type representing values that may be computed " "concurrently and retrieved at a later time." msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:64 +#: doc/guide-tasks.md:62 msgid "" -"[`std::task`]: std/task.html [`std::comm`]: std/comm.html [`std::pipes`]: " -"std/pipes.html [`extra::comm`]: extra/comm.html [`extra::sync`]: extra/sync." -"html [`extra::arc`]: extra/arc.html [`extra::future`]: extra/future.html" +"[`std::task`]: std/task/index.html [`std::comm`]: std/comm/index.html " +"[`extra::comm`]: extra/comm/index.html [`extra::sync`]: extra/sync/index." +"html [`extra::arc`]: extra/arc/index.html [`extra::future`]: extra/future/" +"index.html" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:66 +#: doc/guide-tasks.md:64 +#, fuzzy +#| msgid "# Syntax basics" msgid "# Basics" -msgstr "" +msgstr "# 基本的な構文" #. type: Plain text -#: doc/tutorial-tasks.md:72 +#: doc/guide-tasks.md:70 msgid "" "The programming interface for creating and managing tasks lives in the " "`task` module of the `std` library, and is thus available to all Rust code " @@ -170,12 +165,16 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:76 -msgid "~~~~ # use std::io::println; # use std::task::spawn;" +#: doc/guide-tasks.md:73 doc/guide-tasks.md:132 +#, fuzzy +#| msgid "~~~~ use std::task::spawn;" +msgid "~~~~ # use std::task::spawn;" msgstr "" +"~~~~\n" +"use std::task::spawn;" #. type: Plain text -#: doc/tutorial-tasks.md:80 +#: doc/guide-tasks.md:77 msgid "" "// Print something profound in a different task using a named function fn " "print_message() { println(\"I am running in a different task!\"); } " @@ -183,14 +182,15 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:83 +#: doc/guide-tasks.md:80 msgid "" "// Print something more profound in a different task using a lambda " -"expression spawn( || println(\"I am also running in a different task!\") );" +"expression spawn(proc() println(\"I am also running in a different task!" +"\") );" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:89 +#: doc/guide-tasks.md:86 #, no-wrap msgid "" "// The canonical way to spawn is using `do` notation\n" @@ -201,7 +201,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:95 +#: doc/guide-tasks.md:92 msgid "" "In Rust, there is nothing special about creating tasks: a task is not a " "concept that appears in the language semantics. Instead, Rust's type system " @@ -211,67 +211,43 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:102 +#: doc/guide-tasks.md:99 msgid "" -"The `spawn` function has a very simple type signature: `fn spawn(f: proc())`. " -"Because it accepts only owned closures, and owned closures contain only " -"owned data, `spawn` can safely move the entire closure and all its " +"The `spawn` function has a very simple type signature: `fn spawn(f: " +"proc())`. Because it accepts only owned closures, and owned closures contain " +"only owned data, `spawn` can safely move the entire closure and all its " "associated state into an entirely different task for execution. Like any " "closure, the function passed to `spawn` may capture an environment that it " "carries across tasks." msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:109 +#: doc/guide-tasks.md:105 msgid "" -"~~~ # use std::io::println; # use std::task::spawn; # fn " -"generate_task_number() -> int { 0 } // Generate some state locally let " -"child_task_number = generate_task_number();" +"~~~ # use std::task::spawn; # fn generate_task_number() -> int { 0 } // " +"Generate some state locally let child_task_number = generate_task_number();" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:115 +#: doc/guide-tasks.md:111 #, no-wrap msgid "" "do spawn {\n" -" // Capture it in the remote task\n" -" println(fmt!(\"I am child number %d\", child_task_number));\n" -"}\n" -"~~~\n" -msgstr "" - -#. type: Plain text -#: doc/tutorial-tasks.md:119 -msgid "" -"By default, the scheduler multiplexes tasks across the available cores, " -"running in parallel. Thus, on a multicore machine, running the following " -"code should interleave the output in vaguely random order." -msgstr "" - -#. type: Plain text -#: doc/tutorial-tasks.md:123 -msgid "~~~ # use std::io::print; # use std::task::spawn;" -msgstr "" - -#. type: Plain text -#: doc/tutorial-tasks.md:130 -#, no-wrap -msgid "" -"for child_task_number in range(0, 20) {\n" -" do spawn {\n" -" print(fmt!(\"I am child number %d\\n\", child_task_number));\n" -" }\n" +" // Capture it in the remote task\n" +" println!(\"I am child number {}\", child_task_number);\n" "}\n" "~~~\n" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:132 +#: doc/guide-tasks.md:113 +#, fuzzy +#| msgid "## Conditionals" msgid "## Communication" -msgstr "" +msgstr "## 条件式" #. type: Plain text -#: doc/tutorial-tasks.md:137 +#: doc/guide-tasks.md:118 msgid "" "Now that we have spawned a new task, it would be nice if we could " "communicate with it. Recall that Rust does not have shared mutable state, so " @@ -280,7 +256,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:142 +#: doc/guide-tasks.md:123 msgid "" "A pipe is simply a pair of endpoints: one for sending messages and another " "for receiving messages. Pipes are low-level communication building-blocks " @@ -289,26 +265,21 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:148 +#: doc/guide-tasks.md:129 msgid "" -"The simplest way to create a pipe is to use the `pipes::stream` function to " -"create a `(Port, Chan)` pair. In Rust parlance, a *channel* is a sending " -"endpoint of a pipe, and a *port* is the receiving endpoint. Consider the " -"following example of calculating two results concurrently:" +"The simplest way to create a pipe is to use `Chan::new` function to create a " +"`(Port, Chan)` pair. In Rust parlance, a *channel* is a sending endpoint of " +"a pipe, and a *port* is the receiving endpoint. Consider the following " +"example of calculating two results concurrently:" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:152 -msgid "~~~~ # use std::task::spawn; # use std::comm::{stream, Port, Chan};" +#: doc/guide-tasks.md:134 +msgid "let (port, chan): (Port, Chan) = Chan::new();" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:154 -msgid "let (port, chan): (Port, Chan) = stream();" -msgstr "" - -#. type: Plain text -#: doc/tutorial-tasks.md:159 +#: doc/guide-tasks.md:139 #, no-wrap msgid "" "do spawn || {\n" @@ -318,7 +289,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:165 +#: doc/guide-tasks.md:145 msgid "" "some_other_expensive_computation(); let result = port.recv(); # fn " "some_expensive_computation() -> int { 42 } # fn " @@ -326,7 +297,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:170 +#: doc/guide-tasks.md:150 msgid "" "Let's examine this example in detail. First, the `let` statement creates a " "stream for sending and receiving integers (the left-hand side of the `let`, " @@ -335,14 +306,12 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:175 -msgid "" -"~~~~ # use std::comm::{stream, Chan, Port}; let (port, chan): (Port, " -"Chan) = stream(); ~~~~" +#: doc/guide-tasks.md:154 +msgid "~~~~ let (port, chan): (Port, Chan) = Chan::new(); ~~~~" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:179 +#: doc/guide-tasks.md:158 msgid "" "The child task will use the channel to send data to the parent task, which " "will wait to receive the data on the port. The next statement spawns the " @@ -350,14 +319,13 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:190 +#: doc/guide-tasks.md:168 #, no-wrap msgid "" "~~~~\n" "# use std::task::spawn;\n" -"# use std::comm::stream;\n" "# fn some_expensive_computation() -> int { 42 }\n" -"# let (port, chan) = stream();\n" +"# let (port, chan) = Chan::new();\n" "do spawn || {\n" " let result = some_expensive_computation();\n" " chan.send(result);\n" @@ -366,7 +334,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:196 +#: doc/guide-tasks.md:174 msgid "" "Notice that the creation of the task closure transfers `chan` to the child " "task implicitly: the closure captures `chan` in its environment. Both `Chan` " @@ -376,24 +344,24 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:200 +#: doc/guide-tasks.md:178 msgid "" "Finally, the parent continues with some other expensive computation, then " "waits for the child's result to arrive on the port:" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:209 +#: doc/guide-tasks.md:186 msgid "" -"~~~~ # use std::comm::{stream}; # fn some_other_expensive_computation() {} # " -"let (port, chan) = stream::(); # chan.send(0); " -"some_other_expensive_computation(); let result = port.recv(); ~~~~" +"~~~~ # fn some_other_expensive_computation() {} # let (port, chan) = Chan::" +"::new(); # chan.send(0); some_other_expensive_computation(); let result " +"= port.recv(); ~~~~" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:215 +#: doc/guide-tasks.md:192 msgid "" -"The `Port` and `Chan` pair created by `stream` enables efficient " +"The `Port` and `Chan` pair created by `Chan::new` enables efficient " "communication between a single sender and a single receiver, but multiple " "senders cannot use a single `Chan`, and multiple receivers cannot use a " "single `Port`. What if our example needed to compute multiple results " @@ -401,15 +369,14 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:221 +#: doc/guide-tasks.md:197 msgid "" -"~~~ {.xfail-test} # use std::task::{spawn}; # use std::comm::{stream, Port, " -"Chan}; # fn some_expensive_computation() -> int { 42 } let (port, chan) = " -"stream();" +"~~~ {.xfail-test} # use std::task::{spawn}; # fn " +"some_expensive_computation() -> int { 42 } let (port, chan) = Chan::new();" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:225 +#: doc/guide-tasks.md:201 #, no-wrap msgid "" "do spawn {\n" @@ -418,7 +385,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:232 +#: doc/guide-tasks.md:208 #, no-wrap msgid "" "// ERROR! The previous spawn statement already owns the channel,\n" @@ -430,24 +397,28 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:235 +#: doc/guide-tasks.md:211 msgid "" "Instead we can use a `SharedChan`, a type that allows a single `Chan` to be " "shared by multiple senders." msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:239 -msgid "~~~ # use std::task::spawn; # use std::comm::{stream, SharedChan};" +#: doc/guide-tasks.md:214 +#, fuzzy +#| msgid "~~~~ use std::task::spawn;" +msgid "~~~ # use std::task::spawn;" msgstr "" +"~~~~\n" +"use std::task::spawn;" #. type: Plain text -#: doc/tutorial-tasks.md:242 -msgid "let (port, chan) = stream(); let chan = SharedChan::new(chan);" +#: doc/guide-tasks.md:216 +msgid "let (port, chan) = SharedChan::new();" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:250 +#: doc/guide-tasks.md:224 #, no-wrap msgid "" "for init_val in range(0u, 3) {\n" @@ -460,55 +431,59 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:254 +#: doc/guide-tasks.md:228 msgid "" "let result = port.recv() + port.recv() + port.recv(); # fn " "some_expensive_computation(_i: uint) -> int { 42 } ~~~" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:263 +#: doc/guide-tasks.md:237 msgid "" "Here we transfer ownership of the channel into a new `SharedChan` value. " "Like `Chan`, `SharedChan` is a non-copyable, owned type (sometimes also " "referred to as an *affine* or *linear* type). Unlike with `Chan`, though, " "the programmer may duplicate a `SharedChan`, with the `clone()` method. A " "cloned `SharedChan` produces a new handle to the same channel, allowing " -"multiple tasks to send data to a single port. Between `spawn`, `stream` and " +"multiple tasks to send data to a single port. Between `spawn`, `Chan` and " "`SharedChan`, we have enough tools to implement many useful concurrency " "patterns." msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:268 +#: doc/guide-tasks.md:242 msgid "" "Note that the above `SharedChan` example is somewhat contrived since you " -"could also simply use three `stream` pairs, but it serves to illustrate the " +"could also simply use three `Chan` pairs, but it serves to illustrate the " "point. For reference, written with multiple streams, it might look like the " "example below." msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:273 -msgid "~~~ # use std::task::spawn; # use std::comm::stream; # use std::vec;" +#: doc/guide-tasks.md:246 +#, fuzzy +#| msgid "~~~~ use std::task::spawn;" +msgid "~~~ # use std::task::spawn; # use std::vec;" msgstr "" +"~~~~\n" +"use std::task::spawn;" #. type: Plain text -#: doc/tutorial-tasks.md:282 +#: doc/guide-tasks.md:255 #, no-wrap msgid "" "// Create a vector of ports, one for each child task\n" -"let ports = do vec::from_fn(3) |init_val| {\n" -" let (port, chan) = stream();\n" +"let ports = vec::from_fn(3, |init_val| {\n" +" let (port, chan) = Chan::new();\n" " do spawn {\n" " chan.send(some_expensive_computation(init_val));\n" " }\n" " port\n" -"};\n" +"});\n" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:287 +#: doc/guide-tasks.md:260 msgid "" "// Wait on each port, accumulating the results let result = ports.iter()." "fold(0, |accum, port| accum + port.recv() ); # fn " @@ -516,17 +491,21 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:291 +#: doc/guide-tasks.md:264 msgid "" "## Backgrounding computations: Futures With `extra::future`, rust has a " "mechanism for requesting a computation and getting the result later." msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:299 +#: doc/guide-tasks.md:266 +msgid "The basic example below illustrates this." +msgstr "" + +#. type: Plain text +#: doc/guide-tasks.md:273 #, no-wrap msgid "" -"The basic example below illustrates this.\n" "~~~\n" "# fn make_a_sandwich() {};\n" "fn fib(n: u64) -> u64 {\n" @@ -536,14 +515,14 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:304 +#: doc/guide-tasks.md:278 msgid "" -"let mut delayed_fib = extra::future::spawn (|| fib(50) ); make_a_sandwich(); " -"println(fmt!(\"fib(50) = %?\", delayed_fib.get())) ~~~" +"let mut delayed_fib = extra::future::Future::spawn(proc() fib(50)); " +"make_a_sandwich(); println!(\"fib(50) = {:?}\", delayed_fib.get()) ~~~" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:310 +#: doc/guide-tasks.md:284 msgid "" "The call to `future::spawn` returns immediately a `future` object regardless " "of how long it takes to run `fib(50)`. You can then make yourself a sandwich " @@ -555,11 +534,16 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:322 +#: doc/guide-tasks.md:287 +msgid "" +"Here is another example showing how futures allow you to background " +"computations. The workload will be distributed on the available cores." +msgstr "" + +#. type: Plain text +#: doc/guide-tasks.md:297 #, no-wrap msgid "" -"Here is another example showing how futures allow you to background computations. The workload will\n" -"be distributed on the available cores.\n" "~~~\n" "# use std::vec;\n" "fn partial_sum(start: uint) -> f64 {\n" @@ -572,33 +556,33 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:325 +#: doc/guide-tasks.md:300 #, no-wrap msgid "" "fn main() {\n" -" let mut futures = vec::from_fn(1000, |ind| do extra::future::spawn { partial_sum(ind) });\n" +" let mut futures = vec::from_fn(1000, |ind| do extra::future::Future::spawn { partial_sum(ind) });\n" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:333 +#: doc/guide-tasks.md:308 #, no-wrap msgid "" " let mut final_res = 0f64;\n" " for ft in futures.mut_iter() {\n" " final_res += ft.get();\n" " }\n" -" println(fmt!(\"π^2/6 is not far from : %?\", final_res));\n" +" println!(\"π^2/6 is not far from : {}\", final_res);\n" "}\n" "~~~\n" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:335 +#: doc/guide-tasks.md:310 msgid "## Sharing immutable data without copy: Arc" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:340 +#: doc/guide-tasks.md:315 msgid "" "To share immutable data between tasks, a first approach would be to only use " "pipes as we have seen previously. A copy of the data to share would then be " @@ -607,7 +591,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:344 +#: doc/guide-tasks.md:319 msgid "" "To tackle this issue, one can use an Atomically Reference Counted wrapper " "(`Arc`) as implemented in the `extra` library of Rust. With an Arc, the data " @@ -616,55 +600,59 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:351 +#: doc/guide-tasks.md:322 msgid "" "Here is a small example showing how to use Arcs. We wish to run concurrently " "several computations on a single large vector of floats. Each task needs the " -"full vector to perform its duty. ~~~ # use std::vec; # use std::rand; use " -"extra::arc::Arc;" +"full vector to perform its duty." msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:355 +#: doc/guide-tasks.md:327 +msgid "~~~ # use std::vec; # use std::rand; use extra::arc::Arc;" +msgstr "" + +#. type: Plain text +#: doc/guide-tasks.md:331 #, no-wrap msgid "" -"fn pnorm(nums: &~[float], p: uint) -> float {\n" -" nums.iter().fold(0.0, |a,b| a+(*b).pow(&(p as float)) ).pow(&(1f / (p as float)))\n" +"fn pnorm(nums: &~[f64], p: uint) -> f64 {\n" +" nums.iter().fold(0.0, |a,b| a+(*b).pow(&(p as f64)) ).pow(&(1.0 / (p as f64)))\n" "}\n" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:359 +#: doc/guide-tasks.md:335 #, no-wrap msgid "" "fn main() {\n" -" let numbers = vec::from_fn(1000000, |_| rand::random::());\n" -" println(fmt!(\"Inf-norm = %?\", *numbers.iter().max().unwrap()));\n" +" let numbers = vec::from_fn(1000000, |_| rand::random::());\n" +" println!(\"Inf-norm = {}\", *numbers.iter().max().unwrap());\n" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:361 +#: doc/guide-tasks.md:337 #, no-wrap msgid " let numbers_arc = Arc::new(numbers);\n" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:365 +#: doc/guide-tasks.md:341 #, no-wrap msgid "" " for num in range(1u, 10) {\n" -" let (port, chan) = stream();\n" +" let (port, chan) = Chan::new();\n" " chan.send(numbers_arc.clone());\n" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:374 +#: doc/guide-tasks.md:350 #, no-wrap msgid "" " do spawn {\n" -" let local_arc : Arc<~[float]> = port.recv();\n" +" let local_arc : Arc<~[f64]> = port.recv();\n" " let task_numbers = local_arc.get();\n" -" println(fmt!(\"%u-norm = %?\", num, pnorm(task_numbers, num)));\n" +" println!(\"{}-norm = {}\", num, pnorm(task_numbers, num));\n" " }\n" " }\n" "}\n" @@ -672,45 +660,74 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:396 +#: doc/guide-tasks.md:354 msgid "" "The function `pnorm` performs a simple computation on the vector (it " "computes the sum of its items at the power given as argument and takes the " -"inverse power of this value). The Arc on the vector is created by the line " +"inverse power of this value). The Arc on the vector is created by the line" +msgstr "" + +#. type: Plain text +#: doc/guide-tasks.md:362 +msgid "" "~~~ # use extra::arc::Arc; # use std::vec; # use std::rand; # let numbers = " -"vec::from_fn(1000000, |_| rand::random::()); let numbers_arc=Arc::" -"new(numbers); ~~~ and a clone of it is sent to each task ~~~ # use extra::" -"arc::Arc; # use std::vec; # use std::rand; # let numbers=vec::" -"from_fn(1000000, |_| rand::random::()); # let numbers_arc = Arc::" -"new(numbers); # let (port, chan) = stream(); chan.send(numbers_arc." -"clone()); ~~~ copying only the wrapper and not its contents." +"vec::from_fn(1000000, |_| rand::random::()); let numbers_arc=Arc::" +"new(numbers); ~~~" +msgstr "" + +#. type: Plain text +#: doc/guide-tasks.md:364 +msgid "and a clone of it is sent to each task" +msgstr "" + +#. type: Plain text +#: doc/guide-tasks.md:374 +msgid "" +"~~~ # use extra::arc::Arc; # use std::vec; # use std::rand; # let " +"numbers=vec::from_fn(1000000, |_| rand::random::()); # let numbers_arc " +"= Arc::new(numbers); # let (port, chan) = Chan::new(); chan." +"send(numbers_arc.clone()); ~~~" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:410 +#: doc/guide-tasks.md:376 +msgid "copying only the wrapper and not its contents." +msgstr "" + +#. type: Plain text +#: doc/guide-tasks.md:378 +msgid "Each task recovers the underlying data by" +msgstr "" + +#. type: Plain text +#: doc/guide-tasks.md:390 msgid "" -"Each task recovers the underlying data by ~~~ # use extra::arc::Arc; # use " -"std::vec; # use std::rand; # let numbers=vec::from_fn(1000000, |_| rand::" -"random::()); # let numbers_arc=Arc::new(numbers); # let (port, chan) " -"= stream(); # chan.send(numbers_arc.clone()); # let local_arc : " -"Arc<~[float]> = port.recv(); let task_numbers = local_arc.get(); ~~~ and can " -"use it as if it were local." +"~~~ # use extra::arc::Arc; # use std::vec; # use std::rand; # let " +"numbers=vec::from_fn(1000000, |_| rand::random::()); # let " +"numbers_arc=Arc::new(numbers); # let (port, chan) = Chan::new(); # chan." +"send(numbers_arc.clone()); # let local_arc : Arc<~[f64]> = port.recv(); let " +"task_numbers = local_arc.get(); ~~~" +msgstr "" + +#. type: Plain text +#: doc/guide-tasks.md:392 +msgid "and can use it as if it were local." msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:412 +#: doc/guide-tasks.md:394 msgid "" "The `arc` module also implements Arcs around mutable data that are not " "covered here." msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:414 +#: doc/guide-tasks.md:396 msgid "# Handling task failure" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:423 +#: doc/guide-tasks.md:405 msgid "" "Rust has a built-in mechanism for raising exceptions. The `fail!()` macro " "(which can also be written with an error string as an argument: `fail!" @@ -723,43 +740,21 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:426 -msgid "" -"All tasks are, by default, _linked_ to each other. That means that the fates " -"of all tasks are intertwined: if one fails, so do all the others." -msgstr "" - -#. type: Plain text -#: doc/tutorial-tasks.md:434 -msgid "" -"~~~{.xfail-test .linked-failure} # use std::task::spawn; # use std::task; # " -"fn do_some_work() { loop { task::yield() } } # do task::try { // Create a " -"child task that fails do spawn { fail!() }" -msgstr "" - -#. type: Plain text -#: doc/tutorial-tasks.md:439 -msgid "" -"// This will also fail because the task we spawned failed do_some_work(); " -"# }; ~~~" -msgstr "" - -#. type: Plain text -#: doc/tutorial-tasks.md:449 +#: doc/guide-tasks.md:415 msgid "" "While it isn't possible for a task to recover from failure, tasks may notify " "each other of failure. The simplest way of handling task failure is with the " "`try` function, which is similar to `spawn`, but immediately blocks waiting " -"for the child task to finish. `try` returns a value of type `Result`. `Result` is an `enum` type with two variants: `Ok` and `Err`. In this " -"case, because the type arguments to `Result` are `int` and `()`, callers can " +"for the child task to finish. `try` returns a value of type `Result`. " +"`Result` is an `enum` type with two variants: `Ok` and `Err`. In this case, " +"because the type arguments to `Result` are `int` and `()`, callers can " "pattern-match on a result to check whether it's an `Ok` result with an `int` " "field (representing a successful result) or an `Err` result (representing " "termination with an error)." msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:463 +#: doc/guide-tasks.md:429 #, no-wrap msgid "" "~~~{.xfail-test .linked-failure}\n" @@ -778,7 +773,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:469 +#: doc/guide-tasks.md:435 msgid "" "Unlike `spawn`, the function spawned using `try` may return a value, which " "`try` will dutifully propagate back to the caller in a [`Result`] enum. If " @@ -787,12 +782,12 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:471 -msgid "[`Result`]: std/result.html" +#: doc/guide-tasks.md:437 +msgid "[`Result`]: std/result/index.html" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:476 +#: doc/guide-tasks.md:442 msgid "" "> ***Note:*** A failed task does not currently produce a useful error > " "value (`try` always returns `Err(())`). In the > future, it may be possible " @@ -800,167 +795,30 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:479 +#: doc/guide-tasks.md:445 msgid "" "TODO: Need discussion of `future_result` in order to make failure modes " "useful." msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:487 +#: doc/guide-tasks.md:453 msgid "" "But not all failures are created equal. In some cases you might need to " "abort the entire program (perhaps you're writing an assert which, if it " "trips, indicates an unrecoverable logic error); in other cases you might " "want to contain the failure at a certain boundary (perhaps a small piece of " "input from the outside world, which you happen to be processing in parallel, " -"is malformed and its processing task can't proceed). Hence, you will need " -"different _linked failure modes_." -msgstr "" - -#. type: Plain text -#: doc/tutorial-tasks.md:489 -msgid "## Failure modes" -msgstr "" - -#. type: Plain text -#: doc/tutorial-tasks.md:492 -msgid "" -"By default, task failure is _bidirectionally linked_, which means that if " -"either task fails, it kills the other one." -msgstr "" - -#. type: Plain text -#: doc/tutorial-tasks.md:507 -#, no-wrap -msgid "" -"~~~{.xfail-test .linked-failure}\n" -"# use std::task;\n" -"# use std::comm::oneshot;\n" -"# fn sleep_forever() { loop { let (p, c) = oneshot::<()>(); p.recv(); } }\n" -"# do task::try {\n" -"do spawn {\n" -" do spawn {\n" -" fail!(); // All three tasks will fail.\n" -" }\n" -" sleep_forever(); // Will get woken up by force, then fail\n" -"}\n" -"sleep_forever(); // Will get woken up by force, then fail\n" -"# };\n" -"~~~\n" -msgstr "" - -#. type: Plain text -#: doc/tutorial-tasks.md:514 -msgid "" -"If you want parent tasks to be able to kill their children, but do not want " -"a parent to fail automatically if one of its child task fails, you can call " -"`task::spawn_supervised` for _unidirectionally linked_ failure. The function " -"`task::try`, which we saw previously, uses `spawn_supervised` internally, " -"with additional logic to wait for the child task to finish before returning. " -"Hence:" -msgstr "" - -#. type: Plain text -#: doc/tutorial-tasks.md:536 -#, no-wrap -msgid "" -"~~~{.xfail-test .linked-failure}\n" -"# use std::comm::{stream, Chan, Port};\n" -"# use std::comm::oneshot;\n" -"# use std::task::{spawn, try};\n" -"# use std::task;\n" -"# fn sleep_forever() { loop { let (p, c) = oneshot::<()>(); p.recv(); } }\n" -"# do task::try {\n" -"let (receiver, sender): (Port, Chan) = stream();\n" -"do spawn { // Bidirectionally linked\n" -" // Wait for the supervised child task to exist.\n" -" let message = receiver.recv();\n" -" // Kill both it and the parent task.\n" -" assert!(message != 42);\n" -"}\n" -"do try { // Unidirectionally linked\n" -" sender.send(42);\n" -" sleep_forever(); // Will get woken up by force\n" -"}\n" -"// Flow never reaches here -- parent task was killed too.\n" -"# };\n" -"~~~\n" -msgstr "" - -#. type: Plain text -#: doc/tutorial-tasks.md:542 -msgid "" -"Supervised failure is useful in any situation where one task manages " -"multiple fallible child tasks, and the parent task can recover if any child " -"fails. On the other hand, if the _parent_ (supervisor) fails, then there is " -"nothing the children can do to recover, so they should also fail." -msgstr "" - -#. type: Plain text -#: doc/tutorial-tasks.md:545 -msgid "" -"Supervised task failure propagates across multiple generations even if an " -"intermediate generation has already exited:" -msgstr "" - -#. type: Plain text -#: doc/tutorial-tasks.md:562 -#, no-wrap -msgid "" -"~~~{.xfail-test .linked-failure}\n" -"# use std::task;\n" -"# use std::comm::oneshot;\n" -"# fn sleep_forever() { loop { let (p, c) = oneshot::<()>(); p.recv(); } }\n" -"# fn wait_for_a_while() { for _ in range(0, 1000u) { task::yield() } }\n" -"# do task::try:: {\n" -"do task::spawn_supervised {\n" -" do task::spawn_supervised {\n" -" sleep_forever(); // Will get woken up by force, then fail\n" -" }\n" -" // Intermediate task immediately exits\n" -"}\n" -"wait_for_a_while();\n" -"fail!(); // Will kill grandchild even if child has already exited\n" -"# };\n" -"~~~\n" -msgstr "" - -#. type: Plain text -#: doc/tutorial-tasks.md:565 -msgid "" -"Finally, tasks can be configured to not propagate failure to each other at " -"all, using `task::spawn_unlinked` for _isolated failure_." -msgstr "" - -#. type: Plain text -#: doc/tutorial-tasks.md:581 -#, no-wrap -msgid "" -"~~~{.xfail-test .linked-failure}\n" -"# use std::task;\n" -"# fn random() -> uint { 100 }\n" -"# fn sleep_for(i: uint) { for _ in range(0, i) { task::yield() } }\n" -"# do task::try::<()> {\n" -"let (time1, time2) = (random(), random());\n" -"do task::spawn_unlinked {\n" -" sleep_for(time2); // Won't get forced awake\n" -" fail!();\n" -"}\n" -"sleep_for(time1); // Won't get forced awake\n" -"fail!();\n" -"// It will take MAX(time1,time2) for the program to finish.\n" -"# };\n" -"~~~\n" +"is malformed and its processing task can't proceed)." msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:583 +#: doc/guide-tasks.md:455 msgid "## Creating a task with a bi-directional communication path" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:588 +#: doc/guide-tasks.md:460 msgid "" "A very common thing to do is to spawn a child task where the parent and " "child both need to exchange messages with each other. The function `extra::" @@ -969,7 +827,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:593 +#: doc/guide-tasks.md:465 msgid "" "To see how `DuplexStream()` works, we will create a child task that " "repeatedly receives a `uint` message, converts it to a string, and sends the " @@ -978,7 +836,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:606 +#: doc/guide-tasks.md:478 #, no-wrap msgid "" "~~~{.xfail-test .linked-failure}\n" @@ -996,7 +854,7 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:614 +#: doc/guide-tasks.md:486 msgid "" "The implementation of `DuplexStream` supports both sending and receiving. " "The `stringifier` function takes a `DuplexStream` that can send strings (the " @@ -1007,12 +865,12 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:616 +#: doc/guide-tasks.md:488 msgid "Here is the code for the parent task:" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:630 +#: doc/guide-tasks.md:502 #, no-wrap msgid "" "~~~{.xfail-test .linked-failure}\n" @@ -1031,12 +889,12 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:632 -msgid "let (from_child, to_child) = DuplexStream();" +#: doc/guide-tasks.md:504 +msgid "let (from_child, to_child) = DuplexStream::new();" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:636 +#: doc/guide-tasks.md:508 #, no-wrap msgid "" "do spawn {\n" @@ -1045,23 +903,28 @@ msgid "" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:639 +#: doc/guide-tasks.md:511 msgid "from_child.send(22); assert!(from_child.recv() == ~\"22\");" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:642 +#: doc/guide-tasks.md:514 msgid "from_child.send(23); from_child.send(0);" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:645 +#: doc/guide-tasks.md:517 msgid "" "assert!(from_child.recv() == ~\"23\"); assert!(from_child.recv() == ~\"0\");" msgstr "" #. type: Plain text -#: doc/tutorial-tasks.md:652 +#: doc/guide-tasks.md:520 doc/rust.md:2384 +msgid "# } ~~~~" +msgstr "" + +#. type: Plain text +#: doc/guide-tasks.md:524 msgid "" "The parent task first calls `DuplexStream` to create a pair of bidirectional " "endpoints. It then uses `task::spawn` to create the child task, which " diff --git a/doc/po/ja/guide-testing.md.po b/doc/po/ja/guide-testing.md.po new file mode 100644 index 0000000000000..cf040925ba8a0 --- /dev/null +++ b/doc/po/ja/guide-testing.md.po @@ -0,0 +1,502 @@ +# Japanese translations for Rust package +# Copyright (C) 2014 The Rust Project Developers +# This file is distributed under the same license as the Rust package. +# Automatically generated, 2014. +# +msgid "" +msgstr "" +"Project-Id-Version: Rust 0.9\n" +"POT-Creation-Date: 2014-01-10 12:20+0900\n" +"PO-Revision-Date: 2014-01-10 12:20+0900\n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: ja\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=1; plural=0;\n" + +#. type: Plain text +#: doc/guide-rustpkg.md:255 doc/guide-testing.md:28 +msgid "test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured ~~~" +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:2 +#, fuzzy +#| msgid "% The Rust Language Tutorial" +msgid "% The Rust Testing Guide" +msgstr "% Rust 言語チュートリアル" + +#. type: Plain text +#: doc/guide-testing.md:4 +#, fuzzy +#| msgid "# Getting started" +msgid "# Quick start" +msgstr "# はじめに" + +#. type: Plain text +#: doc/guide-testing.md:6 +msgid "To create test functions, add a `#[test]` attribute like this:" +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:11 +#, no-wrap +msgid "" +"~~~\n" +"fn return_two() -> int {\n" +" 2\n" +"}\n" +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:18 +#, no-wrap +msgid "" +"#[test]\n" +"fn return_two_test() {\n" +" let x = return_two();\n" +" assert!(x == 2);\n" +"}\n" +"~~~\n" +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:20 +msgid "To run these tests, use `rustc --test`:" +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:25 +msgid "" +"~~~ {.notrust} $ rustc --test foo.rs; ./foo running 1 test test " +"return_two_test ... ok" +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:31 +msgid "" +"`rustc foo.rs` will *not* compile the tests, since `#[test]` implies " +"`#[cfg(test)]`. The `--test` flag to `rustc` implies `--cfg test`." +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:34 +msgid "# Unit testing in Rust" +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:37 +msgid "" +"Rust has built in support for simple unit testing. Functions can be marked " +"as unit tests using the 'test' attribute." +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:44 +#, no-wrap +msgid "" +"~~~\n" +"#[test]\n" +"fn return_none_if_empty() {\n" +" // ... test code ...\n" +"}\n" +"~~~\n" +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:52 +msgid "" +"A test function's signature must have no arguments and no return value. To " +"run the tests in a crate, it must be compiled with the '--test' flag: `rustc " +"myprogram.rs --test -o myprogram-tests`. Running the resulting executable " +"will run all the tests in the crate. A test is considered successful if its " +"function returns; if the task running the test fails, through a call to " +"`fail!`, a failed `check` or `assert`, or some other (`assert_eq`, ...) " +"means, then the test fails." +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:55 +msgid "" +"When compiling a crate with the '--test' flag '--cfg test' is also implied, " +"so that tests can be conditionally compiled." +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:65 +#, no-wrap +msgid "" +"~~~\n" +"#[cfg(test)]\n" +"mod tests {\n" +" #[test]\n" +" fn return_none_if_empty() {\n" +" // ... test code ...\n" +" }\n" +"}\n" +"~~~\n" +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:69 +msgid "" +"Additionally #[test] items behave as if they also have the #[cfg(test)] " +"attribute, and will not be compiled when the --test flag is not used." +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:75 +msgid "" +"Tests that should not be run can be annotated with the 'ignore' attribute. " +"The existence of these tests will be noted in the test runner output, but " +"the test will not be run. Tests can also be ignored by configuration so, for " +"example, to ignore a test on windows you can write `#[ignore(cfg(target_os = " +"\"win32\"))]`." +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:80 +msgid "" +"Tests that are intended to fail can be annotated with the 'should_fail' " +"attribute. The test will be run, and if it causes its task to fail then the " +"test will be counted as successful; otherwise it will be counted as a " +"failure. For example:" +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:89 +#, no-wrap +msgid "" +"~~~\n" +"#[test]\n" +"#[should_fail]\n" +"fn test_out_of_bounds_failure() {\n" +" let v: [int] = [];\n" +" v[0];\n" +"}\n" +"~~~\n" +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:95 +msgid "" +"A test runner built with the '--test' flag supports a limited set of " +"arguments to control which tests are run: the first free argument passed to " +"a test runner specifies a filter used to narrow down the set of tests being " +"run; the '--ignored' flag tells the test runner to run only tests with the " +"'ignore' attribute." +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:97 +msgid "## Parallelism" +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:102 +msgid "" +"By default, tests are run in parallel, which can make interpreting failure " +"output difficult. In these cases you can set the `RUST_TEST_TASKS` " +"environment variable to 1 to make the tests run sequentially." +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:104 +msgid "## Benchmarking" +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:112 +msgid "" +"The test runner also understands a simple form of benchmark execution. " +"Benchmark functions are marked with the `#[bench]` attribute, rather than " +"`#[test]`, and have a different form and meaning. They are compiled along " +"with `#[test]` functions when a crate is compiled with `--test`, but they " +"are not run by default. To run the benchmark component of your testsuite, " +"pass `--bench` to the compiled test runner." +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:119 +msgid "" +"The type signature of a benchmark function differs from a unit test: it " +"takes a mutable reference to type `test::BenchHarness`. Inside the benchmark " +"function, any time-variable or \"setup\" code should execute first, followed " +"by a call to `iter` on the benchmark harness, passing a closure that " +"contains the portion of the benchmark you wish to actually measure the per-" +"iteration speed of." +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:125 +msgid "" +"For benchmarks relating to processing/generating data, one can set the " +"`bytes` field to the number of bytes consumed/produced in each iteration; " +"this will used to show the throughput of the benchmark. This must be the " +"amount used in each iteration, *not* the total amount." +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:127 doc/tutorial.md:776 +msgid "For example:" +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:131 +msgid "~~~ extern mod extra; use std::vec;" +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:137 +#, no-wrap +msgid "" +"#[bench]\n" +"fn bench_sum_1024_ints(b: &mut extra::test::BenchHarness) {\n" +" let v = vec::from_fn(1024, |n| n);\n" +" b.iter(|| {v.iter().fold(0, |old, new| old + *new);} );\n" +"}\n" +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:144 +#, no-wrap +msgid "" +"#[bench]\n" +"fn initialise_a_vector(b: &mut extra::test::BenchHarness) {\n" +" b.iter(|| {vec::from_elem(1024, 0u64);} );\n" +" b.bytes = 1024 * 8;\n" +"}\n" +"~~~\n" +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:148 +msgid "" +"The benchmark runner will calibrate measurement of the benchmark function to " +"run the `iter` block \"enough\" times to get a reliable measure of the per-" +"iteration speed." +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:150 +msgid "Advice on writing benchmarks:" +msgstr "" + +#. type: Bullet: ' - ' +#: doc/guide-testing.md:162 +msgid "" +"Move setup code outside the `iter` loop; only put the part you want to " +"measure inside" +msgstr "" + +#. type: Bullet: ' - ' +#: doc/guide-testing.md:162 +msgid "" +"Make the code do \"the same thing\" on each iteration; do not accumulate or " +"change state" +msgstr "" + +#. type: Bullet: ' - ' +#: doc/guide-testing.md:162 +msgid "" +"Make the outer function idempotent too; the benchmark runner is likely to " +"run it many times" +msgstr "" + +#. type: Bullet: ' - ' +#: doc/guide-testing.md:162 +msgid "" +"Make the inner `iter` loop short and fast so benchmark runs are fast and the " +"calibrator can adjust the run-length at fine resolution" +msgstr "" + +#. type: Bullet: ' - ' +#: doc/guide-testing.md:162 +msgid "" +"Make the code in the `iter` loop do something simple, to assist in " +"pinpointing performance improvements (or regressions)" +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:165 +msgid "" +"To run benchmarks, pass the `--bench` flag to the compiled test-runner. " +"Benchmarks are compiled-in but not executed by default." +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:167 +#, fuzzy +#| msgid "## Tuples" +msgid "## Examples" +msgstr "## タプル" + +#. type: Plain text +#: doc/guide-testing.md:169 +#, fuzzy +#| msgid "## Tuple structs" +msgid "### Typical test run" +msgstr "## タプル構造体" + +#. type: Plain text +#: doc/guide-testing.md:172 doc/guide-testing.md:186 +msgid "~~~ {.notrust} > mytests" +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:178 +msgid "" +"running 30 tests running driver::tests::mytest1 ... ok running driver::" +"tests::mytest2 ... ignored ... snip ... running driver::tests::mytest30 ... " +"ok" +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:181 +msgid "result: ok. 28 passed; 0 failed; 2 ignored ~~~ {.notrust}" +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:183 +msgid "### Test run with failures" +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:192 +msgid "" +"running 30 tests running driver::tests::mytest1 ... ok running driver::" +"tests::mytest2 ... ignored ... snip ... running driver::tests::mytest30 ... " +"FAILED" +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:195 +msgid "result: FAILED. 27 passed; 1 failed; 2 ignored ~~~" +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:197 +msgid "### Running ignored tests" +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:200 +msgid "~~~ {.notrust} > mytests --ignored" +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:204 +msgid "" +"running 2 tests running driver::tests::mytest2 ... failed running driver::" +"tests::mytest10 ... ok" +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:207 +msgid "result: FAILED. 1 passed; 1 failed; 0 ignored ~~~" +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:209 +msgid "### Running a subset of tests" +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:212 +msgid "~~~ {.notrust} > mytests mytest1" +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:218 +msgid "" +"running 11 tests running driver::tests::mytest1 ... ok running driver::" +"tests::mytest10 ... ignored ... snip ... running driver::tests::" +"mytest19 ... ok" +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:221 +msgid "result: ok. 11 passed; 0 failed; 1 ignored ~~~" +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:223 +msgid "### Running benchmarks" +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:226 +msgid "~~~ {.notrust} > mytests --bench" +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:230 +msgid "" +"running 2 tests test bench_sum_1024_ints ... bench: 709 ns/iter (+/- 82) " +"test initialise_a_vector ... bench: 424 ns/iter (+/- 99) = 19320 MB/s" +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:233 +msgid "test result: ok. 0 passed; 0 failed; 0 ignored; 2 measured ~~~" +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:235 +#, fuzzy +#| msgid "## Declaring and implementing traits" +msgid "## Saving and ratcheting metrics" +msgstr "## トレイトの宣言と実装" + +#. type: Plain text +#: doc/guide-testing.md:241 +msgid "" +"When running benchmarks or other tests, the test runner can record per-test " +"\"metrics\". Each metric is a scalar `f64` value, plus a noise value which " +"represents uncertainty in the measurement. By default, all `#[bench]` " +"benchmarks are recorded as metrics, which can be saved as JSON in an " +"external file for further reporting." +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:251 +msgid "" +"In addition, the test runner supports _ratcheting_ against a metrics file. " +"Ratcheting is like saving metrics, except that after each run, if the output " +"file already exists the results of the current run are compared against the " +"contents of the existing file, and any regression _causes the testsuite to " +"fail_. If the comparison passes -- if all metrics stayed the same (within " +"noise) or improved -- then the metrics file is overwritten with the new " +"values. In this way, a metrics file in your workspace can be used to ensure " +"your work does not regress performance." +msgstr "" + +#. type: Plain text +#: doc/guide-testing.md:253 +msgid "Test runners take 3 options that are relevant to metrics:" +msgstr "" + +#. type: Bullet: ' - ' +#: doc/guide-testing.md:262 +msgid "" +"`--save-metrics=` will save the metrics from a test run to `file." +"json`" +msgstr "" + +#. type: Bullet: ' - ' +#: doc/guide-testing.md:262 +msgid "" +"`--ratchet-metrics=` will ratchet the metrics against the `file." +"json`" +msgstr "" + +#. type: Bullet: ' - ' +#: doc/guide-testing.md:262 +msgid "" +"`--ratchet-noise-percent=N` will override the noise measurements in `file." +"json`, and consider a metric change less than `N%` to be noise. This can be " +"helpful if you are testing in a noisy environment where the benchmark " +"calibration loop cannot acquire a clear enough signal." +msgstr "" diff --git a/doc/po/ja/index.md.po b/doc/po/ja/index.md.po new file mode 100644 index 0000000000000..5facf3214c417 --- /dev/null +++ b/doc/po/ja/index.md.po @@ -0,0 +1,103 @@ +# Japanese translations for Rust package +# Copyright (C) 2014 The Rust Project Developers +# This file is distributed under the same license as the Rust package. +# Automatically generated, 2014. +# +msgid "" +msgstr "" +"Project-Id-Version: Rust 0.9\n" +"POT-Creation-Date: 2014-01-10 12:20+0900\n" +"PO-Revision-Date: 2014-01-10 12:20+0900\n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: ja\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=1; plural=0;\n" + +#. type: Plain text +#: doc/index.md:2 +msgid "% Rust documentation" +msgstr "" + +#. type: Plain text +#: doc/index.md:8 +msgid "" +"