Laravel for Rust Alpha
laravel-rust-phone
Keep the number your customer typed. Store a consistent number for lookup.
Accept local numbers with a country hint and international numbers with a calling code. Use E.164 for consistent lookup and keep the original spelling when you need to show what the customer entered.
Read the docs Source on GitHub
cargo add laravel-rust-phone- Latest release
- 0.1.0, 2026-12-04
- Maintenance
- Active
- Framework
- laravel-rust 0.2.x
- MSRV
- Rust 1.99 or later
- Licence
- MIT
Validate request fields
Use
PhoneRulewith a companion country field. Restrict accepted countries or number types when a form has specific requirements.Choose how numbers are stored
Use
E164PhoneNumberfor canonical storage orRawPhoneNumberto preserve the submitted text.Check behavior against PHP
The Rust suite runs 179 fixtures generated by Laravel Phone 6.1.0. The parity matrix records intentional differences.
PHP parity
Follows propaganistas/laravel-phone 6.1.0 (commit 7433d79ea4b1). Last verified .
- Parity level
- Full
- Abilities
- 51
- Covered
- 36
- Diverged
- 15
- Planned
- 0
- PHP fixtures
- 179
Fixtures are generated by PHP itself: PHP 8.5, giggsey/libphonenumber-for-php-lite 9.0.44, laravel/framework v13.45.0, propaganistas/laravel-phone 6.1.0.
Coverage by ability
-
number.construct· Covered · Core · 4 testsPhoneNumber::__construct -
number.country· Covered · Core · 9 testsPhoneNumber::getCountry -
number.is-of-country· Covered · Core · 4 testsPhoneNumber::isOfCountry -
number.valid-country· Covered · 6 testsPhoneNumber::isValidCountry -
number.type· Covered · 5 testsPhoneNumber::getType -
number.is-of-type· Covered · 3 testsPhoneNumber::isOfType -
number.normalize-type· Covered · 5 testsPhoneNumber::normalizeType -
number.format· Covered · 2 testsPhoneNumber::format -
number.format-international· Covered · Core · 1 testPhoneNumber::formatInternational -
number.format-national· Covered · Core · 1 testPhoneNumber::formatNational -
number.format-e164· Covered · Core · 10 testsPhoneNumber::formatE164 -
number.format-rfc3966· Covered · 1 testPhoneNumber::formatRFC3966 -
number.normalize-format· Covered · 2 testsPhoneNumber::normalizeFormat -
number.format-from-country· Covered · 5 testsPhoneNumber::formatForCountry -
number.format-mobile-dialing· Covered · 7 testsPhoneNumber::formatForMobileDialingInCountry -
number.valid· Covered · Core · 7 testsPhoneNumber::isValid -
number.lenient· Covered · 2 testsPhoneNumber::lenient -
number.equals· Covered · 3 testsPhoneNumber::equals -
number.not-equals· Covered · 3 testsPhoneNumber::notEquals -
number.raw· Covered · Core · 1 testPhoneNumber::getRawNumber -
number.libphone-object· DivergedPhoneNumber::toLibPhoneObject -
number.to-json· DivergedPhoneNumber::toJson -
number.json-serialize· Covered · 1 testPhoneNumber::jsonSerialize -
number.serialize· DivergedPhoneNumber::__serialize -
number.unserialize· DivergedPhoneNumber::__unserialize -
number.display· Covered · 2 testsPhoneNumber::__toString -
number.macros· DivergedPhoneNumber uses Macroable -
helper.phone· Covered · 2 testsphone($number, $country = null, $format = null) -
rule.data· DivergedPhone::setData -
rule.validate· Diverged · CorePhone::validate -
rule.country· Covered · Core · 2 testsPhone::country -
rule.country-field· Covered · Core · 3 testsPhone::countryField -
rule.type· Covered · 2 testsPhone::type -
rule.not-type· Covered · 2 testsPhone::notType -
rule.mobile· Covered · 2 testsPhone::mobile -
rule.fixed-line· Covered · 2 testsPhone::fixed_line -
rule.lenient· Covered · 1 testPhone::lenient -
rule.international· Covered · 2 testsPhone::international -
rule.parameters· Covered · 8 testsPhone::setParameters -
rule.default-country· DivergedPhone::setDefaultCountry -
rule.alias· DivergedPhoneServiceProvider registers dependent phone rule -
rule.factory· Covered · 1 testPhoneServiceProvider registers Rule::phone -
rule.translation· Divergedvalidation.phone -
provider.discovery· DivergedComposer provider discovery and PhoneServiceProvider::register -
cast.country-hints· Covered · 2 testsPhoneNumberCast::__construct and getPossibleCountries -
cast.e164.get· Covered · Core · 8 testsE164PhoneNumberCast::get -
cast.e164.set· Diverged · CoreE164PhoneNumberCast::set -
cast.e164.serialize· Covered · 2 testsE164PhoneNumberCast::serialize -
cast.raw.get· Diverged · CoreRawPhoneNumberCast::get -
cast.raw.set· Diverged · CoreRawPhoneNumberCast::set -
cast.raw.serialize· DivergedRawPhoneNumberCast::serialize
Differences from PHP (15)
PhoneNumber::toLibPhoneObject- The Rust parser also normalizes Unicode decimal digits such as Devanagari, which PHP 6.1.0 rejects.
PhoneNumber::toJson- Rust serializes canonical phone text as a JSON string; PHP JSON_NUMERIC_CHECK can change the wire type to a number.
PhoneNumber::__serialize- Rust serializes a canonical string through Serde instead of emitting the PHP runtime object format and its number field.
PhoneNumber::__unserialize- Serde restores an E.164 string. PHP runtime object data must first be converted to that string.
PhoneNumber uses Macroable- Rust extension traits provide typed methods. PHP runtime macro registration, mixins, inspection, flushing and dispatch are unavailable.
Phone::setData- An array or object in the country field yields a validation error. PHP 6.1.0 throws a TypeError before handling validation failures.
Phone::validate- Integer-valued decimal input is accepted when it can be represented exactly. Fractional input fails instead of being rounded into a different number by PHP-style string coercion.
Phone::setDefaultCountry- Defaults belong to the rule and its clones, so independent application contexts can use different regions without global state.
PhoneServiceProvider registers dependent phone rule- The Rust framework accepts typed rules. Use the compatibility parameter builder instead of registering a global phone string alias.
validation.phone- The rule renders an application-supplied validation.phone template. It uses an English message when the app supplies no template.
Composer provider discovery and PhoneServiceProvider::register- Apps attach the rule through the framework’s typed validation entry points, which do not use Composer auto-discovery.
E164PhoneNumberCast::set- Typed model writes normalize the value using explicit region hints before setting attributes. PHP reads sibling fields during assignment.
RawPhoneNumberCast::get- Decoding SQL yields the raw column value. Resolve the phone with the selected sibling data when the application needs a PhoneNumber.
RawPhoneNumberCast::set- A missing value binds SQL NULL. PHP converts a missing value to empty text in the raw cast setter.
RawPhoneNumberCast::serialize- Serializing raw storage preserves its text without requiring region resolution. PHP resolves the cast value before model serialization.
In practice
Normalize a Belgian number
Supply the country for national input, then format the same number for storage or display.
use laravel_rust_phone::{Error, phone};
fn main() -> Result<(), Error> {
let number = phone("0470 12 34 56").with_countries(["BE"]);
assert!(number.is_valid());
assert_eq!(number.format_e164()?, "+32470123456");
assert_eq!(number.format_international()?, "+32 470 12 34 56");
assert_eq!(number.format_national()?, "0470 12 34 56");
Ok(())
}Built on
- Laravel-Phone: The package this ports: parsing, validation rules, formatting and model casts, following version 6.1.0.
- phonenumbers-rs: Phone number parsing and formatting in Rust (version 0.1.2).
- Google libphonenumber: The numbering-plan data (version 9.0.44).
Crates: laravel-rust-phone, laravel-rust-phone-core
· Upstream notices
Documentation
- OverviewParse, validate, format, and store phone numbers in Laravel for Rust. The package follows propaganistas/laravel-phone 6.1.0. The package is in alpha.
- Getting startedAdd the crate to your Laravel for Rust project.
- Migrating from PHPInstall the Rust crate. The crate names types and methods in Rust style and uses typed errors for calls that can fail.
- ChangelogWhat changed in each release of laravel-rust-phone: additions, changes and fixes.