Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1c6559f

Browse files
committed
rust: use Bound<T> for keyword arguments
1 parent 92cd24f commit 1c6559f

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

rust-ext/src/compression_parameters.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ impl ZstdCompressionParameters {
249249
}
250250

251251
/// Set parameters from a dictionary of options.
252-
fn set_parameters(&self, kwargs: &PyDict) -> PyResult<()> {
252+
fn set_parameters(&self, kwargs: &Bound<'_, PyDict>) -> PyResult<()> {
253253
unsafe {
254254
zstd_sys::ZSTD_CCtxParams_reset(self.params);
255255
}
@@ -390,7 +390,7 @@ impl ZstdCompressionParameters {
390390
_cls: Bound<'_, PyType>,
391391
py: Python,
392392
args: &Bound<'_, PyTuple>,
393-
kwargs: Option<&PyDict>,
393+
kwargs: Option<&Bound<'_, PyDict>>,
394394
) -> PyResult<Self> {
395395
if args.len() != 1 {
396396
return Err(PyTypeError::new_err(format!(
@@ -402,7 +402,7 @@ impl ZstdCompressionParameters {
402402
let kwargs = if let Some(v) = kwargs {
403403
v.copy()?
404404
} else {
405-
PyDict::new(py)
405+
PyDict::new_bound(py)
406406
};
407407

408408
let level = args.get_item(0)?.extract::<i32>()?;
@@ -446,12 +446,16 @@ impl ZstdCompressionParameters {
446446
kwargs.set_item("strategy", compression_params.strategy as u32)?;
447447
}
448448

449-
Self::new(py, &PyTuple::empty_bound(py), Some(kwargs))
449+
Self::new(py, &PyTuple::empty_bound(py), Some(&kwargs))
450450
}
451451

452452
#[new]
453453
#[pyo3(signature = (* _args, * * kwargs))]
454-
fn new(py: Python, _args: &Bound<'_, PyTuple>, kwargs: Option<&PyDict>) -> PyResult<Self> {
454+
fn new(
455+
py: Python,
456+
_args: &Bound<'_, PyTuple>,
457+
kwargs: Option<&Bound<'_, PyDict>>,
458+
) -> PyResult<Self> {
455459
let params = unsafe { zstd_sys::ZSTD_createCCtxParams() };
456460
if params.is_null() {
457461
return Err(PyMemoryError::new_err("unable to create ZSTD_CCtx_params"));
@@ -462,7 +466,7 @@ impl ZstdCompressionParameters {
462466
let kwargs = if let Some(v) = kwargs {
463467
v.copy()?
464468
} else {
465-
PyDict::new(py)
469+
PyDict::new_bound(py)
466470
};
467471

468472
instance.set_parameters(&kwargs)?;

0 commit comments

Comments
 (0)