Latest states

This commit is contained in:
2026-06-04 01:15:41 -04:00
parent a5ef93b879
commit 578e124d67
4 changed files with 1839 additions and 6 deletions

View File

@@ -27,7 +27,11 @@ from pathlib import Path
from pydantic import BaseModel # type: ignore[import-untyped]
from decoru import emit_rust_struct, walk_pydantic_model # type: ignore[import-untyped]
from decoru import ( # type: ignore[import-untyped]
emit_rust_struct,
to_rust_variant_ident,
walk_pydantic_model,
)
def _declared_in(module, obj) -> bool:
@@ -56,10 +60,6 @@ def discover_enums(module) -> list[type[Enum]]:
]
def _pascal_case(s: str) -> str:
return "".join(part.capitalize() for part in s.split("_") if part)
# Last-variant-is-default matches the catch-all idiom (e.g. `Metadata`
# in `claude_manage.schema.EntryType`). Decoru's `emit_rust_struct`
# emits `impl Default` unconditionally on every BaseModel, so any
@@ -76,7 +76,10 @@ _ENUM_TEMPLATE = textwrap.dedent("""\
def _render_variant(member: Enum, *, is_default: bool) -> str:
pascal = _pascal_case(member.name)
# Pascal-casing the Python member name is the same conversion decoru
# applies when capturing enum field defaults. Sharing the function is
# load-bearing — divergent conversions emit non-compiling schema.rs.
pascal = to_rust_variant_ident(member.name)
default_attr = " #[default]\n" if is_default else ""
return f"{default_attr} {pascal},"