gpui_macros.rs

 1mod derive_into_element;
 2mod derive_render;
 3mod register_action;
 4mod style_helpers;
 5mod test;
 6
 7use proc_macro::TokenStream;
 8
 9/// register_action! can be used to register an action with the GPUI runtime.
10/// You should typically use `gpui::actions!` or `gpui::impl_actions!` instead,
11/// but this can be used for fine grained customization.
12#[proc_macro]
13pub fn register_action(ident: TokenStream) -> TokenStream {
14    register_action::register_action_macro(ident)
15}
16
17/// #[derive(IntoElement)] is used to create a Component out of anything that implements
18/// the `RenderOnce` trait.
19#[proc_macro_derive(IntoElement)]
20pub fn derive_into_element(input: TokenStream) -> TokenStream {
21    derive_into_element::derive_into_element(input)
22}
23
24#[proc_macro_derive(Render)]
25#[doc(hidden)]
26pub fn derive_render(input: TokenStream) -> TokenStream {
27    derive_render::derive_render(input)
28}
29
30/// Used by gpui to generate the style helpers.
31#[proc_macro]
32#[doc(hidden)]
33pub fn style_helpers(input: TokenStream) -> TokenStream {
34    style_helpers::style_helpers(input)
35}
36
37/// #[gpui::test] can be used to annotate test functions that run with GPUI support.
38/// it supports both synchronous and asynchronous tests, and can provide you with
39/// as many `TestAppContext` instances as you need.
40/// The output contains a `#[test]` annotation so this can be used with any existing
41/// test harness (`cargo test` or `cargo-nextest`).
42///
43/// ```
44/// #[gpui::test]
45/// async fn test_foo(mut cx: &TestAppContext) { }
46/// ```
47///
48/// In addition to passing a TestAppContext, you can also ask for a `StdRnd` instance.
49/// this will be seeded with the `SEED` environment variable and is used internally by
50/// the ForegroundExecutor and BackgroundExecutor to run tasks deterministically in tests.
51/// Using the same `StdRng` for behaviour in your test will allow you to exercise a wide
52/// variety of scenarios and interleavings just by changing the seed.
53///
54/// #[gpui::test] also takes three different arguments:
55/// - `#[gpui::test(iterations=10)]` will run the test ten times with a different initial SEED.
56/// - `#[gpui::test(retries=3)]` will run the test up to four times if it fails to try and make it pass.
57/// - `#[gpui::test(on_failure="crate::test::report_failure")]` will call the specified function after the
58///    tests fail so that you can write out more detail about the failure.
59#[proc_macro_attribute]
60pub fn test(args: TokenStream, function: TokenStream) -> TokenStream {
61    test::test(args, function)
62}