Created
March 23, 2022 23:00
-
-
Save manfromth3m0oN/426e55b3961583aa3fa1ea79883fd890 to your computer and use it in GitHub Desktop.
macro rules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use yew::prelude::*; | |
#[function_component(Navbar)] | |
fn child() -> Html { | |
return html! { "I am a child" }; | |
} | |
macro_rules! todo_view { | |
($function:ident => $name:ident) => { | |
#[function_component($name)] | |
fn $function() -> Html { | |
return html! { "I am a " }; | |
} | |
}; | |
($($function:ident => $name:ident),+) => { | |
$(todo_view!($function => $name);)+ | |
}; | |
} | |
todo_view!(player => Player, people => People, playlist => Playlist, controls => Controls); | |
#[function_component(Root)] | |
fn root() -> Html { | |
return html! { <> | |
<Navbar/> | |
<Player/> | |
<People/> | |
<Playlist/> | |
<Controls/> | |
</> | |
}; | |
} | |
fn main() { | |
yew::start_app::<Root>(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment