Search code examples
rustkeyword-argument

What is Python's *Args and **kwargs equivalent in Rust


What is Python's *Args and **kwargs equivalent in Rust

def main(*args, **kwargs):
  pass

Solution

  • Those are variadic arguments and Rust has no direct equivalent. This is because Rust is extremely strongly typed and must know exactly what types will be passed to a function.

    Depending on what you're doing, you'd probably define a function that takes collections; Vec for *args and HashMap for **kwargs. But everything in each collection must be of the same type; a Vec of integers, a HashMap of pairs of strings, etc.