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.

2
  • 3
    Please explain in English words what you are trying to archive! Commented Dec 25, 2020 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. Commented Dec 25, 2020 at 23:22

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.