mirror of
https://github.com/qdrant/qdrant.git
synced 2026-08-04 09:01:00 -05:00
Add doc for #[pyclass_repr] (#8110)
This commit is contained in:
@@ -1,5 +1,45 @@
|
||||
mod pyclass_repr;
|
||||
|
||||
/// `#[pyclass_repr]` - implements `trait Repr`.
|
||||
///
|
||||
/// Only methods with `#[getter]` are included into the output.
|
||||
///
|
||||
/// # Usage example
|
||||
///
|
||||
/// Input:
|
||||
/// ```ignore
|
||||
/// #[pyclass_repr]
|
||||
/// #[pymethods]
|
||||
/// impl PyMyStruct {
|
||||
/// #[getter]
|
||||
/// pub fn foo(&self) -> &str {
|
||||
/// &self.0.foo
|
||||
/// }
|
||||
///
|
||||
/// #[getter]
|
||||
/// pub fn bar(&self) -> f32 {
|
||||
/// self.0.bar
|
||||
/// }
|
||||
///
|
||||
/// pub fn __repr__(&self) -> String {
|
||||
/// self.repr()
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// Generated output is roughly equivalent to:
|
||||
/// ```ignore
|
||||
/// impl crate::repr::Repr for PyMyStruct {
|
||||
/// fn fmt(&self, f: &mut crate::repr::Formatter<'_>) -> std::fmt::Result {
|
||||
/// use crate::repr::WriteExt as _;
|
||||
///
|
||||
/// f.class::<Self>(&[
|
||||
/// ("foo", &self.foo()),
|
||||
/// ("bar", &self.bar()),
|
||||
/// ])
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
#[proc_macro_attribute]
|
||||
pub fn pyclass_repr(
|
||||
_attributes: proc_macro::TokenStream,
|
||||
|
||||
Reference in New Issue
Block a user