#[browser]Expand description
Concise attribute macro alternative to calling __location__ /
__location_async__ directly.
The function name becomes the binding; the PageTemplate is built
from the macro arguments. See the
crate-level documentation and
toolkit_zero_macros::browser for the full argument reference.
§Example
use toolkit_zero::location::browser::{browser, LocationData, LocationError};
async fn run() -> Result<LocationData, LocationError> {
#[browser(title = "My App", tickbox, consent = "I agree")]
fn loc() {}
Ok(loc)
}Replace a decorated fn with an inline location-capture statement.
Available when the location (or location-browser) feature is enabled.
Re-exported as toolkit_zero::location::browser.
The macro wraps either __location__ (with sync) or
__location_async__ (default) and builds the PageTemplate for you.
§Syntax
#[browser] // async, Default template
#[browser(sync)] // blocking, Default template
#[browser(title = "My App")] // async, custom title
#[browser(title = "T", body = "B")] // async, title + body
#[browser(tickbox)] // async, Tickbox template
#[browser(tickbox, title = "T", consent = "C")] // async, Tickbox with args
#[browser(html = "<html>…</html>")] // async, Custom template
#[browser(sync, title = "T")] // sync + any variantAll arguments are optional and may appear in any order.
§Arguments
| Argument | Type | Notes |
|---|---|---|
sync | flag | Use the blocking __location__ function; default uses __location_async__().await |
tickbox | flag | Use PageTemplate::Tickbox; default is PageTemplate::Default |
title = "…" | string literal | Sets the title field on Default or Tickbox |
body = "…" | string literal | Sets the body_text field on Default or Tickbox |
consent = "…" | string literal | Sets the consent_text field on Tickbox only |
html = "…" | string literal | Use PageTemplate::Custom; mutually exclusive with tickbox/title/body/consent |
§What the macro expands to
The function’s name becomes the binding; the body is discarded.
A ? propagates any LocationError.
// Input:
#[browser(title = "My App")]
fn loc() -> LocationData {}
// Expanded to:
let loc = ::toolkit_zero::location::browser::__location_async__(
::toolkit_zero::location::browser::PageTemplate::Default {
title: ::std::option::Option::Some("My App".to_string()),
body_text: ::std::option::Option::None,
}
).await?;Full documentation and examples are in the
crate-level #[browser] section.