# laravel-rust-format

> Rust port of illuminate/support: Laravel's formatting, byte for byte, in Rust.

- Package: laravel-rust-format (Laravel for Rust, alpha), crates: `laravel-rust-format`, `laravel-rust-format-core`
- Maintenance: active; Latest release: 0.1.1 (2026-12-04); Framework: laravel-rust 0.2.x; MSRV: Rust 1.99 or later; Licence: MIT
- Links: [Repository](https://github.com/bowerbird-si/laravel-rust-format), [crates.io](https://crates.io/crates/laravel-rust-format/0.1.1), [docs.rs](https://docs.rs/laravel-rust-format/0.1.1), [Changelog](https://oss.bowerbird.si/format/docs/changelog/), [Contributing](https://github.com/bowerbird-si/laravel-rust-format/blob/16e2c1a95c60fb32c5ee2f37b7d58a9f72be23f7/CONTRIBUTING.md), [Security policy](https://github.com/bowerbird-si/laravel-rust-format/blob/16e2c1a95c60fb32c5ee2f37b7d58a9f72be23f7/SECURITY.md)
- Based on: [Laravel Str, Number and Pluralizer](https://github.com/laravel/framework): The behaviour of Illuminate\Support\Str, Number and Pluralizer, as typed Rust functions with English defaults.; [Carbon](https://github.com/briannesbitt/Carbon): The calendar, formats and relative-time translations, on Jiff with an explicit clock instant. The generated locale tables credit the authors of each language file.; [Doctrine Inflector](https://github.com/doctrine/inflector): English inflection rules, generated into Rust tables.; [Portable ASCII](https://github.com/voku/portable-ascii): Transliteration tables for Str::ascii and Str::slug, generated into Rust tables.; [League CommonMark](https://github.com/thephpleague/commonmark): Reference behaviour for Markdown in the PHP oracle; Comrak renders Markdown in Rust.; [Ramsey UUID](https://github.com/ramsey/uuid): Reference behaviour for identifiers in the PHP oracle; the core builds them in Rust.; [Symfony UID](https://github.com/symfony/uid): Reference behaviour for identifiers in the PHP oracle; the core builds them in Rust.
- PHP parity: core (465 covered, 4 diverged, 3 planned of 472 abilities; 133,206 fixtures; follows illuminate/support 13.39.0; verified 2026-12-04)
- Used in production across multiple projects.
- Community package, not affiliated with Laravel.
- HTML version: https://oss.bowerbird.si/format/
- Documentation: https://oss.bowerbird.si/format/docs.md

Keep the same slugs, labels, amounts and dates when you move code or templates from PHP Laravel to Laravel for Rust. Rust's `format!("{:.2}", 1.005)` prints `1.00`; PHP's `number_format(1.005, 2)` prints `1.01`, and so does this crate.

```shell
cargo add laravel-rust-format
```

- **PHP is the oracle.** PHP runs the conformance cases against pinned Composer packages, and the Rust core must match the fixtures down to raw string bytes and exact float bits.
- **Str, Number and Carbon.** `number_format`, `Str::limit`, `Str::slug`, `Str::plural`, `Number::currency`, Carbon's `format()` and `diffForHumans()`, with PHP's output for the supported inputs.
- **MiniJinja filters.** Register one service provider and write `{{ price|number_currency("EUR") }}` in your views, the way you wrote Blade.
- **A core without the framework.** `laravel-rust-format-core` has no framework dependency: use the same functions in any Rust project.

### The traps it removes

Rust's defaults and PHP's disagree on rounding, float output, display width and transliteration.

```rust
use laravel_rust_format_core::{carbon, number, php, str};

assert_eq!(format!("{:.2}", 1.005), "1.00");
assert_eq!(php::number_format(1.005, 2).unwrap(), "1.01");
assert_eq!(php::echo(0.1 + 0.2), "0.3");

assert_eq!(str::limit("東京", 2), "東...");
assert_eq!(str::slug("Café Mañana & Co."), "cafe-manana-co");
assert_eq!(str::plural("criterion", 2), "criteria");

assert_eq!(number::file_size(1000), "1 KB");
assert_eq!(number::currency(1234.5, "JPY").as_deref(), Some("¥1,234"));

let date: jiff::Timestamp = "2026-12-03T14:30:07Z".parse().unwrap();
assert_eq!(carbon::format(date, "l jS F").unwrap(), "Thursday 3rd December");
```

### In a MiniJinja view

With the service provider registered, templates read the way Blade did.

```jinja
{{ 1.005|number_format(2) }}
{{ "criterion"|str_plural(2) }}
```

### Relative dates, the Carbon way

Carbon has two wordings, and the API keeps them apart: relative to the clock, and relative to another date.

```rust
use laravel_rust_format_core::carbon::{self, DiffForHumans, Relative};

let now: jiff::ZonedDateTime = "2026-12-03T14:30:00+00:00[UTC]".parse().unwrap();
let created: jiff::ZonedDateTime = "2026-11-03T14:30:00+00:00[UTC]".parse().unwrap();
let soon: jiff::ZonedDateTime = "2027-01-02T14:30:00+00:00[UTC]".parse().unwrap();
let seen: jiff::ZonedDateTime = "2026-12-03T12:00:00+00:00[UTC]".parse().unwrap();

// $created->diffForHumans()
assert_eq!(carbon::diff_for_humans(&created, Relative::Now(now.clone())).unwrap(), "1 month ago");
// Carbon counts calendar months: 30 days ahead is still weeks.
assert_eq!(carbon::diff_for_humans(&soon, Relative::Now(now.clone())).unwrap(), "4 weeks from now");
// $created->diffForHumans($soon)
assert_eq!(carbon::diff_for_humans(&created, Relative::To(&soon)).unwrap(), "1 month before");
// diffForHumans(short: true), and parts: 2 with join
assert_eq!(DiffForHumans::new().short().apply(&seen, Relative::Now(now.clone())).unwrap(), "2h ago");
assert_eq!(DiffForHumans::new().parts(2).join().apply(&seen, Relative::Now(now)).unwrap(), "2 hours and 30 minutes ago");
```
