Skip to main content

Crate larust_support

Crate larust_support 

Source
Expand description

Laravel-style top-level helpers. Sits above larust-core/larust-http rather than below them - this is the “batteries-included facade” layer, analogous to Laravel’s helpers.php. Collection<T> lands later.

Re-exports§

pub use axum;
pub use tracing;
pub use serde_json;

Modules§

auth
cache
cashier
Umbrella namespace for subscription billing (laravel/cashier) - one submodule per payment provider backend, each gated behind its own independently-selectable feature (cashier-stripe today; a future cashier-paypal/cashier-square gets its own paypal/square submodule the same way) rather than one shared trait every provider implements - see larust-cashier-stripe’s own doc comment for why a shared interface would be either leaky or lowest-common-denominator thin across providers whose own object models don’t actually agree. An app can enable more than one backend at once; nothing here forces a choice between them.
config_env
Runtime env/env_bool/env_or helpers for generated config/*.rs modules (see larust_convert::config::convert_body) - the runtime half of every Laravel env('VAR')/env('VAR', default) call a config file’s own generated pub fn config() -> serde_json::Value references. Kept in larust-support (not larust-core) for the same “app-facing helper, not framework internals” reason config_helper:: config lives here - this is a distinct, narrower mechanism from that one: config_helper::config resolves a fixed, hand-curated set of Config-struct-backed keys; this module is the raw env-var read a generated config file’s own arbitrary keys fall back to.
console
date
PHP/Laravel-style date() formatting - not a general date-parsing or date-arithmetic library, just enough to format an already-known chrono::DateTime<Utc> using PHP’s own format-character vocabulary (Y, m, d, F, j, S, …), so a converted Blade date('Y-m-d') call reads the same as the Laravel source it came from.
event
image
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).
lang
Not feature-gated - see spa’s own doc comment for the same reasoning: __()/trans() are core Laravel functionality, not a stand-in for a specific optional third-party package the way permission/sanctum/etc. are. larust_http::locale::negotiate (the session-reading half of this) lives with the other opt-in HTTP middleware instead of being re-exported here, matching csrf::verify/ require_auth’s own precedent of being attached via .middleware(...) directly rather than through the facade.
mail
maintenance
Automatic, periodic app-level self-maintenance - distinct from xr clean (which only cleans the local build cache, target/, not anything inside a running app). Session expiry already cleans itself (see larust_http::session’s own hourly background task) and deploy release slots are already pruned after every xr deploy (xr-cli’s own release_slots::prune) - neither needs anything from this module.
notification
orm
preferences
Backs @globals’ persist entries - see larust_http::preferences’ own doc comment for the full design (a dedicated, unsigned, long-lived cookie, deliberately not Session-backed).
push
push_registry
Runtime home for @push/@stack content that needs to cross a boundary compile-time view!(...) resolution can’t see across (a <wire:...> mount, or two view!(...) calls glued by .into_html()) - see larust_view::push_registry’s own doc comment for the full design. Reached by generated codegen the same way larust_support::wire::mount/ larust_support::view::escape already are.
queue
regex_replace
preg_replace($pattern, $replacement, $subject) support - the target of larust-convert’s Blade expression translator (larust_convert:: blade::expr::translate’s "preg_replace" arm). That translator only ever emits a call here after already compiling the same pattern literal with this exact regex crate at convert time (its own self-check, mirroring syn::parse_str::<syn::Expr>’s role everywhere else in that translator) - so replace_all’s pattern argument is never expected to fail to compile for converter-generated call sites. It still doesn’t panic on one that does (a hand-written call, or a pattern edited after conversion): falling back to returning subject unchanged is the same “never fail, best-effort” choice larust_support::date::strtotime already makes, for the same reason - this is a runtime helper, not the converter’s own convert-time rejection path.
repository
The non-SQL half of Larust’s persistence story - see larust_repository::Repository’s own doc comment for the full design (storage-agnostic CRUD, implemented automatically for #[derive(Model)] structs via orm::AnyRepository<T>, by hand for anything else).
schedule
spa
Not feature-gated, unlike [permission]/reverb/sanctum/sitemap/ socialite above - @spa is core template-directive surface (the same tier as wire/push), not a stand-in for an optional third-party Laravel package an app opts into compiling.
storage
strings
PHP string helpers with no direct Rust standard-library equivalent - str::trim/str::len already cover PHP’s trim()/count() on a string, so those translate directly at convert time (larust_convert::blade::expr) without needing anything here. This module exists for the ones that genuinely don’t have a stdlib match.
truthy
PHP’s implicit “truthy” check (if ($x), $x ? ... : ...) - false, 0, 0.0, "", "0", an empty array, and null are falsy; everything else is truthy. Rust’s if/ternary requires a genuine bool and has no equivalent notion, so larust-convert’s Blade expression translator wraps every @if/@elseif/ternary condition in truthy uniformly (larust_convert::blade::expr::translate, the "conditional_expression" arm and blade::scan’s "if"/ "elseif" handling) rather than trying to prove at convert time whether a given condition is already a genuine bool - a real boolean-producing expression ($x == $y, $post->is_published) just passes straight through unchanged (Truthy for bool is the identity), so this is never a behavior change for the already-safe cases, only an enabler for the ones that weren’t.
validation
view
vitex
Larust’s own answer to Laravel’s @vite(...) directive - real integration with the app’s existing Vite/Tailwind toolchain (the laravel-vite-plugin-based vite.config.js/tailwind.config.js/ package.json a converted app’s own resources/assets/ already carries over), not a from-scratch asset bundler. xr convert translates every real @vite([...]) call it finds into a @code/{!! !!} pair calling tags with the exact same entry-point strings - see larust_convert::blade::scan’s own "vite" directive arm.
wire

Macros§

error_view
#[derive(FormRequest)], view!, error_view!, and #[derive(Model)] - re-exported here so generated apps depend only on larust-support, not on larust-macros directly. All four macros’ generated code assumes this re-export path (::larust_support::...). error_view!("404"): compiles resources/views/errors/404.blade.xr if the app defines one, else Larust’s own built-in default page for that status - always produces a String. See error_view.rs’s own doc comment for the override mechanism’s limitations (no context bindings, so no @wire/@can/@role/persist globals, and best kept self-contained rather than @extends-ing a session-aware layout).
view
#[derive(FormRequest)], view!, error_view!, and #[derive(Model)] - re-exported here so generated apps depend only on larust-support, not on larust-macros directly. All four macros’ generated code assumes this re-export path (::larust_support::...). view!("posts.index", { posts }): reads, parses, and resolves resources/views/posts/index.blade.xr (including any @extends layout chain) at compile time, and generates code that renders it into a View. Interpolated expressions ({{ user.name }}) and directive conditions/iterables (@if(...), @foreach(...)) are parsed as real Rust expressions and spliced directly into the generated function body - an undeclared variable is a genuine rustc compile error, not a custom check.

Structs§

Loop
One iteration’s position, alongside the item itself - see WithLoop.
Redirect
RedirectBuilder

Enums§

AppError
Re-exported (not just used internally) so macro-generated code can reference ::larust_support::axum::.../::larust_support::AppError instead of ::larust_core::... - a crate depending on larust-support alone must not need larust-core as a direct dependency just to use a macro. Keep every path in larust-macros’ generated code routed through larust_support for the same reason. default_not_found_html/ default_internal_html are error_view!’s own fallback when no resources/views/errors/{code}.blade.xr override exists. The framework’s primary error type.

Traits§

WithLoop
.with_loop() - wraps any iterator whose length is known up front (ExactSizeIterator, satisfied by .iter() on a Vec/slice/ HashMap, .iter().enumerate() over one of those, and more) into one yielding (item, Loop) pairs.

Functions§

abort
Laravel’s abort(status): builds an AppError for a specific HTTP status, to be returned (typically via ?) from a controller.
asset
Laravel’s asset($path) only differs from url($path) once a separate CDN/ASSET_URL is configured - no such concept exists in this framework yet, so this is a direct delegation, matching Laravel’s own default behavior when no separate asset URL is set. A real, distinct implementation (and its own config field) is a natural addition if a CDN-hosted-assets need ever shows up.
config
Laravel-shaped config('app.name') string lookup - a deliberate, isolated exception to this framework’s usual compile-checked config access (app.config().app_name, still available and still preferred for anything statically known); kept narrow (one match arm per known key) rather than a general dynamic-config system.
default_internal_html
Re-exported (not just used internally) so macro-generated code can reference ::larust_support::axum::.../::larust_support::AppError instead of ::larust_core::... - a crate depending on larust-support alone must not need larust-core as a direct dependency just to use a macro. Keep every path in larust-macros’ generated code routed through larust_support for the same reason. default_not_found_html/ default_internal_html are error_view!’s own fallback when no resources/views/errors/{code}.blade.xr override exists. The framework’s own built-in 500 page. Production-mode only - debug mode (APP_DEBUG=true) never reaches this; see error::debug_page.
default_not_found_html
Re-exported (not just used internally) so macro-generated code can reference ::larust_support::axum::.../::larust_support::AppError instead of ::larust_core::... - a crate depending on larust-support alone must not need larust-core as a direct dependency just to use a macro. Keep every path in larust-macros’ generated code routed through larust_support for the same reason. default_not_found_html/ default_internal_html are error_view!’s own fallback when no resources/views/errors/{code}.blade.xr override exists. The framework’s own built-in 404 page - styled to match the demo app’s branding (see page_shell’s own doc comment for the exact source of the color tokens/copy this mirrors).
redirect
Entry point for Laravel’s redirect() helper.
route
Resolves a named route to its declared path (Laravel’s route($name)). Fails if no route with that name was registered, or if the resolved path still has an unsubstituted {param} placeholder - this function takes no parameters, so a route that needs one (/posts/{post}) must be resolved via route_with instead; erroring here (rather than returning the literal, broken /posts/{post} string) is what steers a caller toward the right function instead of shipping a dead link.
route_with
Resolves a named route, substituting each {key} placeholder in its declared path with the matching value from params (Laravel’s route($name, $params), minus the array/positional-value flexibility - params is explicit (name, value) pairs here, matching this codebase’s existing “explicit, never inferred” stance for anything with this shape, e.g. #[belongs_to_many(...)]’s related_pivot_key or Route::resource’s param argument).
sanitize_rich_text
Sanitizes user-authored HTML (e.g. a rich-text editor’s output) down to a safe subset before it’s persisted or rendered - strips <script>/event-handler attributes/javascript: URLs, keeps ordinary formatting markup (paragraphs, headings, lists, links, images, etc.). Ammonia’s default tag/attribute allowlist matches typical rich-text editor output (Trix, and similar contenteditable-based editors) closely enough to need no custom configuration for this.
url
Builds an absolute URL from path, using the app’s configured APP_URL (Laravel’s url($path)).

Derive Macros§

FormRequest
#[derive(FormRequest)], view!, error_view!, and #[derive(Model)] - re-exported here so generated apps depend only on larust-support, not on larust-macros directly. All four macros’ generated code assumes this re-export path (::larust_support::...). #[derive(FormRequest)]: generates an axum::extract::FromRequest impl that validates a form-urlencoded body against each field’s #[validate(...)] rules before the handler runs, returning a 422 with Laravel-shaped field errors on failure (Laravel’s FormRequest).
Model
#[derive(FormRequest)], view!, error_view!, and #[derive(Model)] - re-exported here so generated apps depend only on larust-support, not on larust-macros directly. All four macros’ generated code assumes this re-export path (::larust_support::...). #[derive(Model)]: generates TABLE/field-name constants, query(), all(), find(id), create(data), and delete(id) over larust-orm’s QueryBuilder, plus route model binding - an axum::extract::FromRequestParts impl so a handler can declare post: Post on a route like /posts/{post} and have it auto-resolved (404 if not found). Requires #[table("...")] on the struct and exactly one #[primary_key] field (currently must be i64). #[route_key("slug")] looks records up by that field instead of the primary key. #[timestamps] (Laravel’s $table->timestamps()) opts into automatic created_at/updated_at population - both must exist as i64 (Unix seconds) fields; create() stamps both, update() re-stamps updated_at only, and neither appears in the generated New* struct, matching Eloquent’s own “never set these yourself” behavior.