How to define a function/method in Rust which accepts at most 2 positional arguments? #1913
Answered
by
birkenfeld
lycantropos
asked this question in
Questions
-
What is an idiomatic way of defining a Rust function which accepts limited number of positional arguments? >>> from rust_module import foo
>>> foo()
>>> foo(1)
>>> foo(1, 2)
>>> foo(1, 2, 3)
Traceback (most recent call last):
File "<input>", line 1, in <module>
TypeError: foo() takes from 0 to 2 positional arguments but 3 were given In Python C API we can use |
Beta Was this translation helpful? Give feedback.
Answered by
birkenfeld
Sep 21, 2021
Replies: 1 comment
-
Like in Python - just take two arguments with one having a default value. Or take |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
davidhewitt
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Like in Python - just take two arguments with one having a default value.
Or take
*args
and extract the contents yourself, this is closer to the C and usingPyArg_UnpackTuple
(which you probably meant).