0

I'm in the process of translation some Rust code to Python. Suppose I have some API in Rust, and methods in Python to call the Rust methods under the hood.

Example Rust (pseudo) code:

struct Args {
    foo: i32,
    bar: f32,
}

pub fn DummyMethod(
    &self,
    args: Args
) -> Result<Data, Error>

Calling this method:

let args = InitTxArgs {
    foo: i32,
    ..Default::default()
};
DummyMethod(args);

In Python I then have:

args = {
    'foo' : 42
    # How do I translate Default here?
}

DummyMethod(args)

How does one translate the ..Default in Rust to Python? I want to specify just the foo field, without specifying the other fields.

Gaston Lagaffe
  • 487
  • 4
  • 7
  • 3
    Please explain in English words what you are trying to archive! – Klaus D. Dec 25 '20 at 19:17
  • Python does not have struct literals, different langages provide different facilities, and your « python » doesn’t make sense. However python does have something similar in « keyword unpacking » / « duct unpacking » (depending on context), `**kwargs`. – Masklinn Dec 25 '20 at 23:22

0 Answers0