Skip to main content

Module image

Module image 

Source
Expand description

Not feature-gated, unlike cashier/[db]/[permission]/etc. above: <Image ...> is core template-directive surface, the same tier as wire/spa (see spa’s own doc comment for the identical reasoning). Backs larust-view’s own <Image src="..." width="..." height="..." /> tag - see larust-image’s own doc comment for the full design (on-demand resize + AVIF/JPEG re-encoding, local images only).

Structs§

ImageOptions
Every <Image ...> attribute, one field each - see this crate’s own doc comment for the full meaning of each one. Owned Strings, not borrowed &strs, deliberately: larust-macros’ own codegen (which constructs this struct literal directly, one field per attribute, no builder calls needed there) hands it a :src="expr" dynamic attribute’s own value exactly as whatever type that expression produces (String, &str, anything Display) - converted uniformly via .to_string() either way - rather than needing a lifetime parameter here just to borrow a value that’s just as often a literal as it is some other owned value computed on the spot. ImageOptions::new/ImageOptions::fill plus the builder-style setters below are for a hand-written Rust call site instead, and accept impl Into<String> so a plain &str literal still needs no extra ceremony there either.
ImagePlugin

Enums§

Loading
"lazy" (default - load when entering the viewport) or "eager" (load immediately). See ImageOptions::loading.
Placeholder
Empty (default - nothing shown while loading) or Blur (a cached blur-up thumbnail behind the image). See ImageOptions::placeholder.

Constants§

DEFAULT_QUALITY
Default JPEG/AVIF quality (1-100) when a call site doesn’t pick one - the same ballpark Next.js’s own default (75) uses: a real size reduction with no visible artifacting for typical photographic content.

Functions§

build_srcset
srcset’s own value when sizes is set - one entry per [SRCSET_BREAKPOINTS] (capped at MAX_DIMENSION), each an aspect-ratio-preserving width-only variant (see optimized_url’s own height: None case) of the same on-demand route the plain src already uses - nothing here is pre-generated; a given breakpoint is decoded/resized/encoded (and cached) only the first time some visitor’s browser actually requests exactly that width.
optimized_url
The URL <Image ...> renders into its src attribute (or one entry of its srcset) - your own app never calls this route directly, this is the one real entry point. src is a path relative to public/ (e.g. "images/hero.jpg" for a file at public/images/hero.jpg) - percent-encoded here so a path containing spaces or other reserved query-string characters still round-trips correctly. height: None requests an aspect-ratio-preserving resize instead of a fixed box (see ResizeTarget::Width) - used for every fill/sizes-driven variant, where only a target width is actually known.
tag
A ready <img> tag - what <Image ...> actually expands to. See this crate’s own doc comment for the full meaning of every ImageOptions field. Takes options by reference - several fields (src in particular) are read more than once below, and ImageOptions owns Strings rather than borrowing &strs (see that struct’s own doc comment for why), so a by-value ImageOptions would mean the first read moved a field a later one still needed.