#[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) implementingtessera_shard::router::RouterDestination - Optional state injection via
#[shard(state = T)], whereT:- Must implement
Default + Send + Sync + 'static - Is constructed (or reused) and exposed as local variable
statewith typetessera_shard::ShardState<T>
- Must implement
- 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 ispop()‑ed - Override:
#[shard(lifecycle = scope)]to persist for the lifetime of the current router controller hosted byshard_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 = Tis configured, shard state is injected as local variablestateand does not appear in the function signature.
§Errors
Emits a compile error if unsupported lifecycle is provided, or if
lifecycle is used without state.