From 4269f524ba80aaca8d9b068d7fa32dd3a12bc7db Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Fri, 2 Aug 2024 13:01:27 -0400 Subject: [PATCH] Add small doc on blueprint macro --- cursive-macros/src/builder/dummy_mod.rs | 1 + cursive-macros/src/lib.rs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/cursive-macros/src/builder/dummy_mod.rs b/cursive-macros/src/builder/dummy_mod.rs index 00b3fa4e..ef5a1130 100644 --- a/cursive-macros/src/builder/dummy_mod.rs +++ b/cursive-macros/src/builder/dummy_mod.rs @@ -5,6 +5,7 @@ pub fn blueprint(_: TokenStream, _: TokenStream) -> TokenStream { TokenStream::new() } +// Just return the annotated function unchanged. pub fn callback_helpers(item: TokenStream) -> TokenStream { item } diff --git a/cursive-macros/src/lib.rs b/cursive-macros/src/lib.rs index 45594954..4c5de420 100644 --- a/cursive-macros/src/lib.rs +++ b/cursive-macros/src/lib.rs @@ -80,6 +80,23 @@ pub fn callback_helpers(_attrs: TokenStream, item: TokenStream) -> TokenStream { } /// Defines a blueprint for creating a view from config. +/// +/// It should be added to a type which defines how to build the view. +/// +/// # Examples +/// +/// ```rust,ignore +/// #[cursive::blueprint(TextView::empty())] +/// struct BlueprintForTextview { +/// content: StyledString, +/// } +/// ``` +/// +/// This recipe will: +/// * Create a base view with `TextView::empty()`. +/// * Look for a `content` key in the given config. +/// * Try to resolve the associated value to a `StyledString`. +/// * Call `set_content` on the base with the resulting `StyledString`. #[proc_macro_attribute] pub fn blueprint(attrs: TokenStream, item: TokenStream) -> TokenStream { builder::blueprint(attrs, item)