@@ -9,13 +9,11 @@ use crate::foundations::{
99 cast, func, repr, scope, ty, Array , Dict , FromValue , IntoValue , Repr , Str , Value ,
1010} ;
1111
12- /// Captured arguments to a function.
12+ /// 関数に渡された引数。
1313///
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`型になります。この型は、位置引数と名前付き引数の両方にアクセスするためのメソッドを提供しています。
1917///
2018/// ```example
2119/// #let format(title, ..authors) = {
@@ -29,9 +27,8 @@ use crate::foundations::{
2927/// #format("ArtosFlow", "Jane", "Joe")
3028/// ```
3129///
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`演算子を使うと、関数呼び出しにおいて引数や配列、辞書を展開して渡すことができます。
3532///
3633/// ```example
3734/// #let array = (2, 3, 5)
@@ -43,15 +40,14 @@ use crate::foundations::{
4340#[ derive( Clone , Hash ) ]
4441#[ allow( clippy:: derived_hash_with_manual_eq) ]
4542pub 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+ /// 関数呼び出し箇所のスパン。これは引数リスト自体のスパンではなく、関数呼び出し全体のものです。
4844 pub span : Span ,
4945 /// The positional and named arguments.
5046 pub items : EcoVec < Arg > ,
5147}
5248
5349impl Args {
54- /// Create positional arguments from a span and values.
50+ /// スパンと値から位置引数を作成します。
5551 pub fn new < T : IntoValue > ( span : Span , values : impl IntoIterator < Item = T > ) -> Self {
5652 let items = values
5753 . into_iter ( )
@@ -64,20 +60,20 @@ impl Args {
6460 Self { span, items }
6561 }
6662
67- /// Attach a span to these arguments if they don't already have one.
63+ /// 引数にスパンがアタッチされていない場合はアタッチします。
6864 pub fn spanned ( mut self , span : Span ) -> Self {
6965 if self . span . is_detached ( ) {
7066 self . span = span;
7167 }
7268 self
7369 }
7470
75- /// Returns the number of remaining positional arguments.
71+ /// 残りの位置引数の個数を返します。
7672 pub fn remaining ( & self ) -> usize {
7773 self . items . iter ( ) . filter ( |slot| slot. name . is_none ( ) ) . count ( )
7874 }
7975
80- /// Insert a positional argument at a specific index.
76+ /// 指定したインデックスに位置引数を挿入します。
8177 pub fn insert ( & mut self , index : usize , span : Span , value : Value ) {
8278 self . items . insert (
8379 index,
@@ -89,7 +85,7 @@ impl Args {
8985 )
9086 }
9187
92- /// Push a positional argument.
88+ /// 位置引数をプッシュします。
9389 pub fn push ( & mut self , span : Span , value : Value ) {
9490 self . items . push ( Arg {
9591 span : self . span ,
@@ -98,7 +94,7 @@ impl Args {
9894 } )
9995 }
10096
101- /// Consume and cast the first positional argument if there is one.
97+ /// 最初の位置引数がある場合、それを取り出してキャストします。
10298 pub fn eat < T > ( & mut self ) -> SourceResult < Option < T > >
10399 where
104100 T : FromValue < Spanned < Value > > ,
@@ -113,7 +109,7 @@ impl Args {
113109 Ok ( None )
114110 }
115111
116- /// Consume n positional arguments if possible.
112+ /// 可能ならn個の位置引数を取り出します。
117113 pub fn consume ( & mut self , n : usize ) -> SourceResult < Vec < Arg > > {
118114 let mut list = vec ! [ ] ;
119115
@@ -133,10 +129,9 @@ impl Args {
133129 Ok ( list)
134130 }
135131
136- /// Consume and cast the first positional argument.
132+ /// 最初の位置引数を取り出してキャストします。
137133 ///
138- /// Returns a `missing argument: {what}` error if no positional argument is
139- /// left.
134+ /// 位置引数が残っていなければ、`missing argument: {what}`エラーを返します。
140135 pub fn expect < T > ( & mut self , what : & str ) -> SourceResult < T >
141136 where
142137 T : FromValue < Spanned < Value > > ,
@@ -147,7 +142,7 @@ impl Args {
147142 }
148143 }
149144
150- /// The error message for missing arguments.
145+ /// 引数が足りない場合のエラーメッセージ。
151146 fn missing_argument ( & self , what : & str ) -> SourceDiagnostic {
152147 for item in & self . items {
153148 let Some ( name) = item. name . as_deref ( ) else { continue } ;
@@ -295,9 +290,9 @@ impl Args {
295290
296291#[ scope]
297292impl Args {
298- /// Construct spreadable arguments in place.
293+ /// 展開可能な引数をその場で生成します。
299294 ///
300- /// This function behaves like `{let args(..sink) = sink}`.
295+ /// この関数は、 `{let args(..sink) = sink}`のように動作します。
301296 ///
302297 /// ```example
303298 /// #let args = arguments(stroke: red, inset: 1em, [Body])
@@ -306,27 +301,23 @@ impl Args {
306301 #[ func( constructor) ]
307302 pub fn construct (
308303 args : & mut Args ,
309- /// The arguments to construct.
304+ /// 作成する引数。
310305 #[ external]
311306 #[ variadic]
312307 arguments : Vec < Value > ,
313308 ) -> Args {
314309 args. take ( )
315310 }
316311
317- /// Returns the positional argument at the specified index, or the named
318- /// argument with the specified name.
312+ /// 指定したインデックスの位置引数、または指定した名前の名前付き引数を返します。
319313 ///
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`]を呼ぶのと同等です。
324315 #[ func]
325316 pub fn at (
326317 & self ,
327- /// The index or name of the argument to get.
318+ /// 取得する引数のインデックスまたは名前。
328319 key : ArgumentKey ,
329- /// A default value to return if the key is invalid.
320+ /// キーが無効な場合に返すデフォルト値。
330321 #[ named]
331322 default : Option < Value > ,
332323 ) -> StrResult < Value > {
@@ -336,7 +327,7 @@ impl Args {
336327 . ok_or_else ( || missing_key_no_default ( key) )
337328 }
338329
339- /// Returns the captured positional arguments as an array.
330+ /// 渡された位置引数を配列の形で返します。
340331 #[ func( name = "pos" , title = "Positional" ) ]
341332 pub fn to_pos ( & self ) -> Array {
342333 self . items
@@ -346,7 +337,7 @@ impl Args {
346337 . collect ( )
347338 }
348339
349- /// Returns the captured named arguments as a dictionary.
340+ /// 渡された名前付き引数を辞書の形で返します。
350341 #[ func( name = "named" ) ]
351342 pub fn to_named ( & self ) -> Dict {
352343 self . items
0 commit comments