comparison rust/hg-cpython/src/revlog.rs @ 51199:16d477bb0078

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.
author Georges Racinet <georges.racinet@octobus.net>
date Sat, 30 Sep 2023 16:15:56 +0200
parents 52bbb57a76ad
children 7434747343ab
comparison
equal deleted inserted replaced
51198:52bbb57a76ad 51199:16d477bb0078
216 216
217 /// return a binary packed version of the header 217 /// return a binary packed version of the header
218 def pack_header(&self, *args, **kw) -> PyResult<PyObject> { 218 def pack_header(&self, *args, **kw) -> PyResult<PyObject> {
219 let rindex = self.index(py).borrow(); 219 let rindex = self.index(py).borrow();
220 let packed = rindex.pack_header(args.get_item(py, 0).extract(py)?); 220 let packed = rindex.pack_header(args.get_item(py, 0).extract(py)?);
221 let packed = PyBytes::new(py, &packed).into_object(); 221 let rust_res = PyBytes::new(py, &packed).into_object();
222 let cpacked = self.call_cindex(py, "pack_header", args, kw)?; 222
223 assert_py_eq(py, "pack_header", &packed, &cpacked)?; 223 let c_res = self.call_cindex(py, "pack_header", args, kw)?;
224 Ok(packed) 224 assert_py_eq(py, "pack_header", &rust_res, &c_res)?;
225 Ok(rust_res)
225 } 226 }
226 227
227 /// get an index entry 228 /// get an index entry
228 def get(&self, *args, **kw) -> PyResult<PyObject> { 229 def get(&self, *args, **kw) -> PyResult<PyObject> {
229 self.call_cindex(py, "get", args, kw) 230 self.call_cindex(py, "get", args, kw)