Add doc for #[pyclass_repr] (#8110)

This commit is contained in:
xzfc
2026-02-12 14:48:15 +00:00
committed by timvisee
parent 0951e03c5f
commit 88c51ae772
3 changed files with 42 additions and 0 deletions

View File

@@ -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,

View File

@@ -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;

View File

@@ -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()) {