1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//! 账号信息。
//!
//! 更多信息参考 [`AccountInfo`]。

use pyo3::{prelude::*, types::*};

/// 账号信息。
///
/// # Python
/// ```python
/// class AccountInfo:
///     @property
///     def nickname(self) -> str: ...
///     @property
///     def age(self) -> int: ...
///     @property
///     def gender(self) -> int: ...
/// ```
#[pyclass]
#[derive(Debug, Clone)]
pub struct AccountInfo {
    /// 昵称。
    #[pyo3(get)]
    pub nickname: Py<PyString>,

    /// 年龄。
    #[pyo3(get)]
    pub age: u8,

    /// 性别。
    #[pyo3(get)]
    pub gender: u8,
}

#[pymethods]
impl AccountInfo {
    fn __repr__(&self) -> String {
        Python::with_gil(|py| {
            format!(
                "AccountInfo(nickname={:?}, age={:?}, gender={:?})",
                self.nickname.as_ref(py).repr().unwrap(),
                self.age,
                self.gender
            )
        })
    }
}