4
4
< meta charset ="utf-8 ">
5
5
< meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6
6
< meta name ="generator " content ="rustdoc ">
7
- < title > Attributes </ title >
7
+ < title > アトリビュート </ title >
8
8
9
9
< link rel ="stylesheet " type ="text/css " href ="rustbook.css ">
10
10
185
185
< div id ='page '>
186
186
187
187
188
- < h1 class ="title "> Attributes</ h1 >
189
- < p > Declarations can be annotated with ‘attributes’ in Rust. They look like this:</ p >
188
+ < h1 class ="title "> アトリビュート</ h1 >
189
+ <!-- % Attributes -->
190
+
191
+ <!-- Declarations can be annotated with ‘attributes’ in Rust. They look like this: -->
192
+
193
+ < p > Rustでは以下のように「アトリビュート」によって宣言を修飾することができます。</ p >
190
194
< span class ='rusttest '> fn main() {
191
195
#[test]
192
196
fn foo() {}
193
197
}</ span > < pre class ='rust rust-example-rendered '>
194
198
< span class ='attribute '> #[< span class ='ident '> test</ span > ]</ span > </ pre >
195
199
196
- < p > or like this:</ p >
200
+ <!-- or like this: -->
201
+
202
+ < p > または以下のように:</ p >
197
203
< span class ='rusttest '> fn main() {
198
204
mod foo {
199
205
#![test]
200
206
}
201
207
}</ span > < pre class ='rust rust-example-rendered '>
202
208
< span class ='attribute '> #< span class ='op '> !</ span > [< span class ='ident '> test</ span > ]</ span > </ pre >
203
209
204
- < p > The difference between the two is the < code > !</ code > , which changes what the attribute
205
- applies to:</ p >
210
+ <!-- The difference between the two is the `!`, which changes what the attribute -->
211
+
212
+ <!-- applies to: -->
213
+
214
+ < p > 2つの違いは < code > !</ code > に有ります、 < code > !</ code > はアトリビュートが適用されるものを変更します:</ p >
206
215
< span class ='rusttest '> fn main() {
207
216
#[foo]
208
217
struct Foo;
@@ -218,12 +227,21 @@ <h1 class="title">Attributes</h1>
218
227
< span class ='attribute '> #< span class ='op '> !</ span > [< span class ='ident '> bar</ span > ]</ span >
219
228
}</ pre >
220
229
221
- < p > The < code > #[foo]</ code > attribute applies to the next item, which is the < code > struct</ code >
222
- declaration. The < code > #![bar]</ code > attribute applies to the item enclosing it, which is
223
- the < code > mod</ code > declaration. Otherwise, they’re the same. Both change the meaning of
224
- the item they’re attached to somehow.</ p >
230
+ <!-- The `#[foo]` attribute applies to the next item, which is the `struct` -->
231
+
232
+ <!-- declaration. The `#![bar]` attribute applies to the item enclosing it, which is -->
233
+
234
+ <!-- the `mod` declaration. Otherwise, they’re the same. Both change the meaning of -->
235
+
236
+ <!-- the item they’re attached to somehow. -->
237
+
238
+ < p > < code > #[foo]</ code > アトリビュートは次のアイテムに適用され、この場合は < code > struct</ code > 宣言に適用されます。
239
+ < code > #![bar]</ code > アトリビュートは < code > #![bar]</ code > アトリビュートを囲んでいるアイテムに適用され、この場合は < code > mod</ code > 宣言に適用されます。
240
+ その他の点については同じであり、どちらも適用されたアイテムの意味を変化させます。</ p >
225
241
226
- < p > For example, consider a function like this:</ p >
242
+ <!-- For example, consider a function like this: -->
243
+
244
+ < p > 例を挙げると、たとえば以下の様な関数では:</ p >
227
245
< span class ='rusttest '> fn main() {
228
246
#[test]
229
247
fn check() {
@@ -235,11 +253,18 @@ <h1 class="title">Attributes</h1>
235
253
< span class ='macro '> assert_eq</ span > < span class ='macro '> !</ span > (< span class ='number '> 2</ span > , < span class ='number '> 1</ span > < span class ='op '> +</ span > < span class ='number '> 1</ span > );
236
254
}</ pre >
237
255
238
- < p > It is marked with < code > #[test]</ code > . This means it’s special: when you run
239
- < a href ="testing.html "> tests</ a > , this function will execute. When you compile as usual, it won’t
240
- even be included. This function is now a test function.</ p >
256
+ <!-- It is marked with `#[test]`. This means it’s special: when you run -->
257
+
258
+ <!-- [tests][tests], this function will execute. When you compile as usual, it won’t -->
259
+
260
+ <!-- even be included. This function is now a test function. -->
261
+
262
+ < p > この関数は < code > #[test]</ code > によってマークされており、これは [テスト][tests] を走らせた時に実行されるという特別な意味になります。
263
+ 通常通りにコンパイルをした場合は、コンパイル結果に含まれません。この関数は今やテスト関数なのです。</ p >
264
+
265
+ <!-- Attributes may also have additional data: -->
241
266
242
- < p > Attributes may also have additional data :</ p >
267
+ < p > アトリビュートは以下のように、追加のデータを持つことができます :</ p >
243
268
< span class ='rusttest '> fn main() {
244
269
#[inline(always)]
245
270
fn super_fast_fn() {
@@ -248,7 +273,9 @@ <h1 class="title">Attributes</h1>
248
273
< span class ='attribute '> #[< span class ='ident '> inline</ span > (< span class ='ident '> always</ span > )]</ span >
249
274
< span class ='kw '> fn</ span > < span class ='ident '> super_fast_fn</ span > () {</ pre >
250
275
251
- < p > Or even keys and values:</ p >
276
+ <!-- Or even keys and values: -->
277
+
278
+ < p > また、キーと値についても持つことができます:</ p >
252
279
< span class ='rusttest '> fn main() {
253
280
#[cfg(target_os = "macos")]
254
281
mod macos_only {
@@ -257,9 +284,15 @@ <h1 class="title">Attributes</h1>
257
284
< span class ='attribute '> #[< span class ='ident '> cfg</ span > (< span class ='ident '> target_os</ span > < span class ='op '> =</ span > < span class ='string '> "macos"</ span > )]</ span >
258
285
< span class ='kw '> mod</ span > < span class ='ident '> macos_only</ span > {</ pre >
259
286
260
- < p > Rust attributes are used for a number of different things. There is a full list
261
- of attributes < a href ="../reference.html#attributes "> in the reference</ a > . Currently, you are not allowed to
262
- create your own attributes, the Rust compiler defines them.</ p >
287
+ <!-- Rust attributes are used for a number of different things. There is a full list -->
288
+
289
+ <!-- of attributes [in the reference][reference]. Currently, you are not allowed to -->
290
+
291
+ <!-- create your own attributes, the Rust compiler defines them. -->
292
+
293
+ < p > Rustのアトリビュートは様々なことに利用されます。
294
+ すべてのアトリビュートのリストは [リファレンス][reference] に載っています。
295
+ 現在は、Rustコンパイラーによって定義されている以外の独自のアトリビュートを作成することは許可されていません。</ p >
263
296
264
297
< script type ="text/javascript ">
265
298
window . playgroundUrl = "https://play.rust-lang.org" ;
0 commit comments