extendr / extendr/extendr.github.io
default value of arguments
- Dominant language
- JavaScript
- Stars
- 10
- Forks
- 8
- Avg merge
- 20h 26m
- Merged PRs (30d)
- 5
Description
Maybe related to extendr/extendr#576
It would be great if we could set default values for the arguments as is possible with pyo3.
https://pyo3.rs/main/function/signature
```rs
use pyo3::types::{PyDict, PyTuple};
#[pymethods]
impl MyClass {
#[new]
#[pyo3(signature = (num=-1))]
fn new(num: i32) -> Self {
MyClass { num }
}
#[pyo3(signature = (num=10, *py_args, name="Hello", **py_kwargs))]
fn method(
&mut self,
num: i32,
py_args: &PyTuple,
name: &str,
py_kwargs: Option<&PyDict>,
) -> String {
let num_before = self.num;
self.num = num;
format!(
"num={} (was previously={}), py_args={:?}, name={}, py_kwargs={:?} ",
num, num_before, py_args, name, py_kwargs,
)
}
fn make_change(&mut self, num: i32) -> PyResult {
self.num = num;
Ok(format!("num={}", self.num))
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.