Skip to content

Commit

Permalink
feat: impl AddAnyAttr trait for Static<V> (#3464)
Browse files Browse the repository at this point in the history
* Implement AddAnyAttr trait for Static<V>

Closes #3463

* [autofix.ci] apply automated fixes

---------

Co-authored-by: geoffreygarrett <[email protected]>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 10, 2025
1 parent 723685c commit 7d9cd43
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions tachys/src/view/static_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ impl<const V: &'static str> RenderHtml for Static<V> {
}

impl<const V: &'static str> AddAnyAttr for Static<V> {
type Output<SomeNewAttr: Attribute> = Static<V>;
type Output<NewAttr: Attribute> = Static<V>;

fn add_any_attr<NewAttr: Attribute>(
self,
Expand All @@ -229,7 +229,15 @@ impl<const V: &'static str> AddAnyAttr for Static<V> {
where
Self::Output<NewAttr>: RenderHtml,
{
todo!()
// inline helper function to assist the compiler with type inference
#[inline(always)]
const fn create_static<const S: &'static str, A: Attribute>(
) -> <Static<S> as AddAnyAttr>::Output<A> {
Static
}

// call the helper function with the current const value and new attribute type
create_static::<V, NewAttr>()
}
}

Expand Down

0 comments on commit 7d9cd43

Please sign in to comment.