fix(py): explicit getter/setter for user name

This commit is contained in:
zaaarf 2024-10-16 03:47:07 +02:00
parent 8b2a2f2e2e
commit 7cc8e88402
No known key found for this signature in database
GPG key ID: 102E445F4C3F829B
2 changed files with 11 additions and 1 deletions

View file

@ -12,7 +12,6 @@ pub struct User {
/// User unique identifier, should never change. /// User unique identifier, should never change.
pub id: Uuid, pub id: Uuid,
/// User name, can change but should be unique. /// User name, can change but should be unique.
#[cfg_attr(any(feature = "py", feature = "py-noabi"), pyo3(get, set))]
pub name: String, pub name: String,
} }

View file

@ -170,6 +170,17 @@ impl User {
Ok(()) Ok(())
} }
#[getter]
fn get_name(&self) -> pyo3::PyResult<String> {
Ok(self.name.clone())
}
#[setter]
fn set_name(&mut self, value: String) -> pyo3::PyResult<()> {
self.name = value;
Ok(())
}
fn __str__(&self) -> String { fn __str__(&self) -> String {
format!("{self:?}") format!("{self:?}")
} }