shard

Attribute Macro shard 

Source
#[shard]
Expand description

Transforms a function into a shard component that can be navigated to via the routing system and (optionally) provided with a lazily‑initialized per‑shard state.

§Features

  • Generates a StructNameDestination (UpperCamelCase + Destination) implementing tessera_ui::router::RouterDestination
  • Optional state injection via #[shard(state = T)], where T:
    • Must implement Default + Send + Sync + 'static
    • Is constructed (or reused) and exposed as local variable state with type tessera_shard::ShardState<T>
  • Produces a stable shard ID: module_path!()::function_name

§Lifecycle

Controlled by the lifecycle shard attribute argument.

  • Default: Shard – state is removed when the destination is pop()‑ed
  • Override: #[shard(lifecycle = scope)] to persist for the lifetime of the current router controller hosted by shard_home

Route-scoped state is removed on route pop/clear. Scope-scoped state is removed when the hosting shard_home is dropped.

§Parameter Transformation

  • Function parameters are treated as explicit destination props.
  • When state = T is configured, shard state is injected as local variable state and does not appear in the function signature.

§Generated Destination (Conceptual)

struct ProfilePageDestination { /* non-state params as public fields */ }
impl RouterDestination for ProfilePageDestination {
    fn exec_component(&self) { profile_page(/* fields */); }
    fn shard_id(&self) -> &'static str { "<module>::profile_page" }
}

§Limitations

  • Do not manually implement RouterDestination for these pages; rely on generation

§See Also

  • Routing helpers: tessera_ui::router::{shard_home, router_outlet}
  • Router controller internals: tessera_ui::router::RouterController

§Errors

Emits a compile error if unsupported lifecycle is provided, or if lifecycle is used without state.