Skip to main content

Module preferences

Module preferences 

Source
Expand description

Long-lived, unsigned, client-writable preference cookies - backing @globals’ persist entries (persist theme = "dark", see docs/MACROS.md). Deliberately not the session cookie (session.rs): that one is scoped to the current browser session (Expiry::OnSessionEnd by default - no .with_expiry(...) call anywhere in this crate) and rotates on every login (Session::cycle_id(), see larust_auth::guard::login) - the wrong lifetime for a preference that should survive both. Also deliberately not signed/encrypted (axum_extra’s PrivateCookieJar/ SignedCookieJar): tampering with your own theme preference has no security consequence, so the Key-management complexity those add isn’t worth it here.

Read-only from the server’s side, by design - the write path is the browser setting document.cookie directly (the same “no server round trip for a purely-local UI preference” reasoning already applies to a plain client-side toggle), not a POST endpoint this module would need to expose. See demo/resources/views/layouts/app.blade.xr’s theme-toggle script for the real write side.

Structs§

CookieJar
Extractor that grabs cookies from the request and manages the jar.

Functions§

get
Reads a persist global’s current value - None when the browser never set it (a first visit, or the user cleared cookies), in which case the @globals block’s own fallback expression is what actually renders. See larust_macros’s Node::PersistGlobal codegen arm, the only caller this function is really designed for.