Always clone on in getters

Since copy implies clone, this doesn't  code.
This commit is contained in:
konstin 2018-06-12 17:47:24 +02:00
parent 7fbe13d97f
commit 60d1565a8f
3 changed files with 9 additions and 2 deletions

View File

@ -1,5 +1,9 @@
# Changelog # Changelog
## Unreleased
* Always clone in getters. This allows using the get-annotation on all Clone-Types
## 0.2.7 (2018-05-18) ## 0.2.7 (2018-05-18)
* Fix nightly breakage with proc_macro_path * Fix nightly breakage with proc_macro_path

View File

@ -302,7 +302,7 @@ fn impl_descriptors(
quote! { quote! {
impl #cls { impl #cls {
fn #name(&self) -> _pyo3::PyResult<#field_ty> { fn #name(&self) -> _pyo3::PyResult<#field_ty> {
Ok(self.#name) Ok(self.#name.clone())
} }
} }
} }

View File

@ -54,6 +54,8 @@ fn class_with_properties() {
struct GetterSetter { struct GetterSetter {
#[prop(get, set)] #[prop(get, set)]
num: i32, num: i32,
#[prop(get, set)]
text: String,
token: PyToken token: PyToken
} }
@ -70,8 +72,9 @@ fn getter_setter_autogen() {
let gil = Python::acquire_gil(); let gil = Python::acquire_gil();
let py = gil.python(); let py = gil.python();
let inst = py.init(|t| GetterSetter{num: 10, token: t}).unwrap(); let inst = py.init(|t| GetterSetter{num: 10, token: t, text: "Hello".to_string()}).unwrap();
py_run!(py, inst, "assert inst.num == 10"); py_run!(py, inst, "assert inst.num == 10");
py_run!(py, inst, "inst.num = 20; assert inst.num == 20"); py_run!(py, inst, "inst.num = 20; assert inst.num == 20");
py_run!(py, inst, "assert inst.text == 'Hello'; inst.text = 'There'; assert inst.text == 'There'");
} }