leptos icon indicating copy to clipboard operation
leptos copied to clipboard

`leptos_macro` hygiene

Open jquesada2016 opened this issue 2 years ago • 1 comments

We need to optimize hygiene as much as possible for both the view! and #[component] macros until macros 2.0 make life easier. Specifically, we should:

  • Convert all imports to absolute paths. For example, instead of leptos::ev::click, we should use ::leptos::ev::click. This ensures that the import is unambiguously absolute to the crate.
  • Explicitly reference all trait methods, such as Clone, IntoView, etc., as they cannot be assumed to be in scope. For example, instead of value.clone(), we should use ::core::clone::Clone::clone(&value).
  • Minimize the use of imports from std to facilitate support for #![no_std] environments, such as embedded microcontrollers in the future.
  • Remove all macro panics from view! and use proc_macro_error macros instead to improve DX.

jquesada2016 avatar Jan 03 '23 14:01 jquesada2016

In terms of review

Points 1-2 make sense and appear frequently in guides on "how to write macros". Points 3-4 make sense and I think should be regarded as good rules.

I think this is a good idea.

martinfrances107 avatar Jan 24 '23 11:01 martinfrances107