Summary
Add compile-time protection to prevent calling .id() multiple times on the same ElementBuilder.
Motivation
When building complex UI patterns, it's easy to accidentally call .id() twice. This bug is silent and hard to catch.
Proposed API
Use type-state pattern with phantom types to enforce single .id() call:
pub struct NoId;
pub struct WithId;
pub fn id(self) -> ElementBuilder<'ply, WithId, CustomElementData> {
// ...
}
Add a .getId() -> &Id to ElementBuilder<'ply, WithId, CustomElementData> to let the user check the established Id.
Keep other builder methods ambiguous.
Behavior
- First
.id() call transitions the builder's type state to WithId
- Subsequent
.id() calls are compile-time errors
.getId() lets the user check the established Id
- All other builder methods work in both
NoId and WithId states
- Elements without explicit
.id() calls continue to work as before
Summary
Add compile-time protection to prevent calling
.id()multiple times on the sameElementBuilder.Motivation
When building complex UI patterns, it's easy to accidentally call
.id()twice. This bug is silent and hard to catch.Proposed API
Use type-state pattern with phantom types to enforce single
.id()call:Add a
.getId() -> &IdtoElementBuilder<'ply, WithId, CustomElementData>to let the user check the established Id.Keep other builder methods ambiguous.
Behavior
.id()call transitions the builder's type state toWithId.id()calls are compile-time errors.getId()lets the user check the established IdNoIdandWithIdstates.id()calls continue to work as before