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