# HG changeset patch # User Georges Racinet # Date 2023-09-30 14:15:56 # Node ID 16d477bb007845e19e3b227d70c7c22216b9dbbf # Parent 52bbb57a76ad1bc9ac8d64fc50e0edc0c277b759 rust-index: return variables systematic naming convention To help knowing at a glance when a method is ready, making us more comofortable when we are close to the final removal of scaffolding, we introduce the systematic variable names `rust_res` and `c_res`. The goal of this series is to always return the formet. We take again the case of `pack_header` as example. Our personal opinion is to usually avoid such poor semantics as `res`, but usually accept it when it close to the actual return, which will be the case in most methods of this series. Also, the name can simply be dropped when we remove the scaffolding. To follow on the example, the body of `pack_header()` should become this in the final version: ``` let index = self.index(py).borrow(); let packed = index.pack_header(args.get_item(py, 0).extract(py)?); Ok(PyBytes::new(py, &packed).into_object()); ``` in these cases it is close to the actual return and will be removed at the end entirely. diff --git a/rust/hg-cpython/src/revlog.rs b/rust/hg-cpython/src/revlog.rs --- a/rust/hg-cpython/src/revlog.rs +++ b/rust/hg-cpython/src/revlog.rs @@ -218,10 +218,11 @@ py_class!(pub class MixedIndex |py| { def pack_header(&self, *args, **kw) -> PyResult { let rindex = self.index(py).borrow(); let packed = rindex.pack_header(args.get_item(py, 0).extract(py)?); - let packed = PyBytes::new(py, &packed).into_object(); - let cpacked = self.call_cindex(py, "pack_header", args, kw)?; - assert_py_eq(py, "pack_header", &packed, &cpacked)?; - Ok(packed) + let rust_res = PyBytes::new(py, &packed).into_object(); + + let c_res = self.call_cindex(py, "pack_header", args, kw)?; + assert_py_eq(py, "pack_header", &rust_res, &c_res)?; + Ok(rust_res) } /// get an index entry