@@ -9,13 +9,11 @@ use crate::foundations::{
9
9
cast, func, repr, scope, ty, Array , Dict , FromValue , IntoValue , Repr , Str , Value ,
10
10
} ;
11
11
12
- /// Captured arguments to a function.
12
+ /// 関数に渡された引数。
13
13
///
14
- /// # Argument Sinks
15
- /// Like built-in functions, custom functions can also take a variable number of
16
- /// arguments. You can specify an _argument sink_ which collects all excess
17
- /// arguments as `..sink`. The resulting `sink` value is of the `arguments`
18
- /// type. It exposes methods to access the positional and named arguments.
14
+ /// # 引数シンク
15
+ /// 組み込み関数と同様に、カスタム関数も可変長引数を受け取れます。
16
+ /// 余分にある引数をすべてまとめて受け取る _引数シンク_(キッチンシンクのようにさまざまなものが流れ込む先)は、`..sink`の形で指定できます。このとき生成される`sink`の値は`arguments`型になります。この型は、位置引数と名前付き引数の両方にアクセスするためのメソッドを提供しています。
19
17
///
20
18
/// ```example
21
19
/// #let format(title, ..authors) = {
@@ -29,9 +27,8 @@ use crate::foundations::{
29
27
/// #format("ArtosFlow", "Jane", "Joe")
30
28
/// ```
31
29
///
32
- /// # Spreading
33
- /// Inversely to an argument sink, you can _spread_ arguments, arrays and
34
- /// dictionaries into a function call with the `..spread` operator:
30
+ /// # 引数の展開
31
+ /// 引数シンクとは逆に、`..spread`演算子を使うと、関数呼び出しにおいて引数や配列、辞書を展開して渡すことができます。
35
32
///
36
33
/// ```example
37
34
/// #let array = (2, 3, 5)
@@ -43,15 +40,14 @@ use crate::foundations::{
43
40
#[ derive( Clone , Hash ) ]
44
41
#[ allow( clippy:: derived_hash_with_manual_eq) ]
45
42
pub struct Args {
46
- /// The callsite span for the function. This is not the span of the argument
47
- /// list itself, but of the whole function call.
43
+ /// 関数呼び出し箇所のスパン。これは引数リスト自体のスパンではなく、関数呼び出し全体のものです。
48
44
pub span : Span ,
49
45
/// The positional and named arguments.
50
46
pub items : EcoVec < Arg > ,
51
47
}
52
48
53
49
impl Args {
54
- /// Create positional arguments from a span and values.
50
+ /// スパンと値から位置引数を作成します。
55
51
pub fn new < T : IntoValue > ( span : Span , values : impl IntoIterator < Item = T > ) -> Self {
56
52
let items = values
57
53
. into_iter ( )
@@ -64,20 +60,20 @@ impl Args {
64
60
Self { span, items }
65
61
}
66
62
67
- /// Attach a span to these arguments if they don't already have one.
63
+ /// 引数にスパンがアタッチされていない場合はアタッチします。
68
64
pub fn spanned ( mut self , span : Span ) -> Self {
69
65
if self . span . is_detached ( ) {
70
66
self . span = span;
71
67
}
72
68
self
73
69
}
74
70
75
- /// Returns the number of remaining positional arguments.
71
+ /// 残りの位置引数の個数を返します。
76
72
pub fn remaining ( & self ) -> usize {
77
73
self . items . iter ( ) . filter ( |slot| slot. name . is_none ( ) ) . count ( )
78
74
}
79
75
80
- /// Insert a positional argument at a specific index.
76
+ /// 指定したインデックスに位置引数を挿入します。
81
77
pub fn insert ( & mut self , index : usize , span : Span , value : Value ) {
82
78
self . items . insert (
83
79
index,
@@ -89,7 +85,7 @@ impl Args {
89
85
)
90
86
}
91
87
92
- /// Push a positional argument.
88
+ /// 位置引数をプッシュします。
93
89
pub fn push ( & mut self , span : Span , value : Value ) {
94
90
self . items . push ( Arg {
95
91
span : self . span ,
@@ -98,7 +94,7 @@ impl Args {
98
94
} )
99
95
}
100
96
101
- /// Consume and cast the first positional argument if there is one.
97
+ /// 最初の位置引数がある場合、それを取り出してキャストします。
102
98
pub fn eat < T > ( & mut self ) -> SourceResult < Option < T > >
103
99
where
104
100
T : FromValue < Spanned < Value > > ,
@@ -113,7 +109,7 @@ impl Args {
113
109
Ok ( None )
114
110
}
115
111
116
- /// Consume n positional arguments if possible.
112
+ /// 可能ならn個の位置引数を取り出します。
117
113
pub fn consume ( & mut self , n : usize ) -> SourceResult < Vec < Arg > > {
118
114
let mut list = vec ! [ ] ;
119
115
@@ -133,10 +129,9 @@ impl Args {
133
129
Ok ( list)
134
130
}
135
131
136
- /// Consume and cast the first positional argument.
132
+ /// 最初の位置引数を取り出してキャストします。
137
133
///
138
- /// Returns a `missing argument: {what}` error if no positional argument is
139
- /// left.
134
+ /// 位置引数が残っていなければ、`missing argument: {what}`エラーを返します。
140
135
pub fn expect < T > ( & mut self , what : & str ) -> SourceResult < T >
141
136
where
142
137
T : FromValue < Spanned < Value > > ,
@@ -147,7 +142,7 @@ impl Args {
147
142
}
148
143
}
149
144
150
- /// The error message for missing arguments.
145
+ /// 引数が足りない場合のエラーメッセージ。
151
146
fn missing_argument ( & self , what : & str ) -> SourceDiagnostic {
152
147
for item in & self . items {
153
148
let Some ( name) = item. name . as_deref ( ) else { continue } ;
@@ -295,9 +290,9 @@ impl Args {
295
290
296
291
#[ scope]
297
292
impl Args {
298
- /// Construct spreadable arguments in place.
293
+ /// 展開可能な引数をその場で生成します。
299
294
///
300
- /// This function behaves like `{let args(..sink) = sink}`.
295
+ /// この関数は、 `{let args(..sink) = sink}`のように動作します。
301
296
///
302
297
/// ```example
303
298
/// #let args = arguments(stroke: red, inset: 1em, [Body])
@@ -306,27 +301,23 @@ impl Args {
306
301
#[ func( constructor) ]
307
302
pub fn construct (
308
303
args : & mut Args ,
309
- /// The arguments to construct.
304
+ /// 作成する引数。
310
305
#[ external]
311
306
#[ variadic]
312
307
arguments : Vec < Value > ,
313
308
) -> Args {
314
309
args. take ( )
315
310
}
316
311
317
- /// Returns the positional argument at the specified index, or the named
318
- /// argument with the specified name.
312
+ /// 指定したインデックスの位置引数、または指定した名前の名前付き引数を返します。
319
313
///
320
- /// If the key is an [integer]($int), this is equivalent to first calling
321
- /// [`pos`]($arguments.pos) and then [`array.at`]. If it is a [string]($str),
322
- /// this is equivalent to first calling [`named`]($arguments.named) and then
323
- /// [`dictionary.at`].
314
+ /// キーが[整数型]($int)の場合、それはまず[`pos`]($arguments.pos)メソッドを呼んでから、次に[`array.at`]を呼ぶのと同等です。キーが[文字列型]($str)である場合、まず[`named`]($arguments.named)メソッドを呼び、次に[`dictionary.at`]を呼ぶのと同等です。
324
315
#[ func]
325
316
pub fn at (
326
317
& self ,
327
- /// The index or name of the argument to get.
318
+ /// 取得する引数のインデックスまたは名前。
328
319
key : ArgumentKey ,
329
- /// A default value to return if the key is invalid.
320
+ /// キーが無効な場合に返すデフォルト値。
330
321
#[ named]
331
322
default : Option < Value > ,
332
323
) -> StrResult < Value > {
@@ -336,7 +327,7 @@ impl Args {
336
327
. ok_or_else ( || missing_key_no_default ( key) )
337
328
}
338
329
339
- /// Returns the captured positional arguments as an array.
330
+ /// 渡された位置引数を配列の形で返します。
340
331
#[ func( name = "pos" , title = "Positional" ) ]
341
332
pub fn to_pos ( & self ) -> Array {
342
333
self . items
@@ -346,7 +337,7 @@ impl Args {
346
337
. collect ( )
347
338
}
348
339
349
- /// Returns the captured named arguments as a dictionary.
340
+ /// 渡された名前付き引数を辞書の形で返します。
350
341
#[ func( name = "named" ) ]
351
342
pub fn to_named ( & self ) -> Dict {
352
343
self . items
0 commit comments