waterui_core/components/
label.rs

1//! This module provides implementations of the `View` trait for common string types,
2//! allowing them to be used directly as views in the UI system.
3
4use alloc::{borrow::Cow, string::String};
5use waterui_str::Str;
6
7use crate::View;
8
9/// A macro that implements the `View` trait for multiple string types.
10///
11/// This macro takes a list of types and implements the `View` trait for each of them,
12/// converting the type to a `Str` for rendering.
13macro_rules! impl_label {
14    ($($ty:ty),*) => {
15        $(
16            impl View for $ty {
17                fn body(self, _env: &crate::Environment) -> impl View {
18                    Str::from(self)
19                }
20            }
21
22        )*
23    };
24}
25
26// Implement `View` for common string types
27impl_label!(&'static str, String, Cow<'static, str>);
28
29// Define Str as a raw view
30raw_view!(Str);