Getting started

laravel-rust-format Alpha Laravel for Rust

Used in production across multiple projects.

Install laravel-rust-format-core for Rust functions or laravel-rust-format for the Laravel for Rust provider and MiniJinja filters. Both require Rust 1.99 or later. See install for the Git dependency before the first release.

Format a number and a label

The modules follow their PHP equivalents. Rust uses snake case and keeps the integer or float type at the call site.

use laravel_rust_format_core::{php, str};

let amount = php::number_format(1234.5, 2).unwrap(); // "1,234.50"
let label = str::plural_with_count("city", 3); // "3 cities"

assert_eq!(amount, "1,234.50");
assert_eq!(label, "3 cities");

Use a builder for options such as Laravel’s preserveWords.

use laravel_rust_format_core::str::Limit;

let summary = Limit::new(8).end("…").preserve_words().apply("Visit Lisbon");
assert_eq!(summary, "Visit…");

Use the helpers from a view

Register the provider and pass numbers, strings and dates in the view context. This MiniJinja template uses literal values so you can also paste it into a view as a smoke test.

{{ 1234.5|number_format(2) }} {# 1,234.50 #}
{{ "city"|str_plural(3) }} {# cities #}

The adapter re-exports the Rust functions at laravel_rust_format::core. You can format values in a view model and pass strings to the template, or call the filters directly.

Community package, not affiliated with Laravel.