Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
Kayak UI
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Microhacks
Bevy Forks
Kayak UI
Commits
667a9521
Commit
667a9521
authored
3 years ago
by
MrGVSV
Browse files
Options
Downloads
Patches
Plain Diff
Documented macros
parent
ff99bb60
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
kayak_render_macros/src/lib.rs
+30
-1
30 additions, 1 deletion
kayak_render_macros/src/lib.rs
with
30 additions
and
1 deletion
kayak_render_macros/src/lib.rs
+
30
−
1
View file @
667a9521
...
@@ -25,6 +25,8 @@ use widget::ConstructedWidget;
...
@@ -25,6 +25,8 @@ use widget::ConstructedWidget;
use
crate
::
widget
::
Widget
;
use
crate
::
widget
::
Widget
;
use
crate
::
widget_props
::
impl_widget_props
;
use
crate
::
widget_props
::
impl_widget_props
;
/// A top level macro that works the same as [`rsx`] but provides some additional
/// context for building the root widget.
#[proc_macro]
#[proc_macro]
#[proc_macro_error]
#[proc_macro_error]
pub
fn
render
(
input
:
TokenStream
)
->
TokenStream
{
pub
fn
render
(
input
:
TokenStream
)
->
TokenStream
{
...
@@ -43,7 +45,8 @@ pub fn render(input: TokenStream) -> TokenStream {
...
@@ -43,7 +45,8 @@ pub fn render(input: TokenStream) -> TokenStream {
TokenStream
::
from
(
result
)
TokenStream
::
from
(
result
)
}
}
/// Generate a renderable widget tree, before rendering it
/// A proc macro that turns RSX syntax into structure constructors and calls the
/// context to create the widgets.
#[proc_macro]
#[proc_macro]
#[proc_macro_error]
#[proc_macro_error]
pub
fn
rsx
(
input
:
TokenStream
)
->
TokenStream
{
pub
fn
rsx
(
input
:
TokenStream
)
->
TokenStream
{
...
@@ -52,6 +55,7 @@ pub fn rsx(input: TokenStream) -> TokenStream {
...
@@ -52,6 +55,7 @@ pub fn rsx(input: TokenStream) -> TokenStream {
TokenStream
::
from
(
result
)
TokenStream
::
from
(
result
)
}
}
/// A proc macro that turns RSX syntax into structure constructors only.
#[proc_macro]
#[proc_macro]
#[proc_macro_error]
#[proc_macro_error]
pub
fn
constructor
(
input
:
TokenStream
)
->
TokenStream
{
pub
fn
constructor
(
input
:
TokenStream
)
->
TokenStream
{
...
@@ -61,6 +65,15 @@ pub fn constructor(input: TokenStream) -> TokenStream {
...
@@ -61,6 +65,15 @@ pub fn constructor(input: TokenStream) -> TokenStream {
TokenStream
::
from
(
result
)
TokenStream
::
from
(
result
)
}
}
/// This attribute macro is what allows Rust functions to be generated into
/// valid widgets structs.
///
/// # Examples
///
/// ```
/// #[widget]
/// fn MyWidget() { /* ... */ }
/// ```
#[proc_macro_attribute]
#[proc_macro_attribute]
#[proc_macro_error]
#[proc_macro_error]
pub
fn
widget
(
args
:
TokenStream
,
item
:
TokenStream
)
->
TokenStream
{
pub
fn
widget
(
args
:
TokenStream
,
item
:
TokenStream
)
->
TokenStream
{
...
@@ -75,6 +88,7 @@ pub fn widget(args: TokenStream, item: TokenStream) -> TokenStream {
...
@@ -75,6 +88,7 @@ pub fn widget(args: TokenStream, item: TokenStream) -> TokenStream {
function_component
::
create_function_widget
(
f
,
widget_args
)
function_component
::
create_function_widget
(
f
,
widget_args
)
}
}
/// A derive macro for the `WidgetProps` trait
#[proc_macro_derive(WidgetProps,
attributes(prop_field))]
#[proc_macro_derive(WidgetProps,
attributes(prop_field))]
#[proc_macro_error]
#[proc_macro_error]
pub
fn
derive_widget_props
(
item
:
TokenStream
)
->
TokenStream
{
pub
fn
derive_widget_props
(
item
:
TokenStream
)
->
TokenStream
{
...
@@ -222,6 +236,21 @@ pub fn use_effect(input: TokenStream) -> TokenStream {
...
@@ -222,6 +236,21 @@ pub fn use_effect(input: TokenStream) -> TokenStream {
effect
.build
()
effect
.build
()
}
}
/// Helper method for getting the core crate
///
/// Depending on the usage of the macro, this will become `crate`, `kayak_core`,
/// or `kayak_ui::core`.
///
/// # Examples
///
/// ```
/// fn my_macro() -> proc_macro2::TokenStream {
/// let kayak_core = get_core_crate();
/// quote! {
/// let foo = #kayak_core::Foo;
/// }
/// }
/// ```
fn
get_core_crate
()
->
proc_macro2
::
TokenStream
{
fn
get_core_crate
()
->
proc_macro2
::
TokenStream
{
let
found_crate
=
proc_macro_crate
::
crate_name
(
"kayak_core"
);
let
found_crate
=
proc_macro_crate
::
crate_name
(
"kayak_core"
);
if
let
Ok
(
found_crate
)
=
found_crate
{
if
let
Ok
(
found_crate
)
=
found_crate
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment