mirror of
https://github.com/qdrant/qdrant.git
synced 2026-07-23 11:11: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,
|
||||
|
||||
@@ -4,6 +4,7 @@ use std::fmt;
|
||||
pub use edge_py_codegen::pyclass_repr;
|
||||
use pyo3::PyTypeInfo;
|
||||
|
||||
/// Can be implemented using [macro pyclass_repr].
|
||||
pub trait Repr {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result;
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ use proc_macro::TokenStream;
|
||||
|
||||
mod anonymize;
|
||||
|
||||
/// Grep for `trait Anonymize` for doc.
|
||||
#[proc_macro_derive(Anonymize, attributes(anonymize))]
|
||||
pub fn derive_anonymize(input: TokenStream) -> TokenStream {
|
||||
match anonymize::derive_anonymize(input.into()) {
|
||||
|
||||
Reference in New Issue
Block a user