You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A #[host_module] type declares the ---@trait interfaces it implements, and a Rust trait is declared to Teal as one #570
A Rust host type exposed through #[host_module] cannot say in Teal that it implements a ---@trait interface (#564). A Teal function written <T is Shape>, or one taking a Shape, therefore cannot accept a host value even when the host implements every method. Going the other way, a Rust trait that the host wants Teal code to implement has no Teal declaration.
Evidence
Read from the code, not reproduced:
#[host_module] writes its .d.tl "from a plain impl block" (crates/htl-macros/src/lib.rs:6). Its sibling #[c_export] refuses a trait impl outright: "c_export: put it on the inherent impl block, not on a trait impl" (crates/htl-macros/src/lib.rs:1957).
The .d.tl it writes declares a record per host type, with no is clause (crates/htl-core/src/dts.rs, "What each Rust shape becomes").
Proposal
Two halves, which can land separately:
A host type implements a Teal trait.#[host_module(impls = [Shape])] (spelling to be decided) adds is Shape to the record the .d.tl declares for the type. The trait-impl lint then checks the host's methods against the trait as it checks a Teal record's.
Alternative: the host writes the is and the interface by hand in a separate .d.tl. That is the hand-written copy #[host_module] exists to avoid.
Acceptance
A #[host_module] type marked as implementing Shape gets is Shape in the written .d.tl. A Teal function <T is Shape>(x: T) accepts the host value without a cast.
If that host type lacks a method of Shape, htl check reports trait-impl (or the macro fails to compile), naming the type and the method.
A Rust trait with the new attribute is written as a ---@trait interface in the .d.tl. A Teal record that is it and leaves out a method gets the trait-impl finding.
htl dts writes the same declarations without a build, as it does for #[host_module] today.
Activity