This page maps each ruudvdd/ogm call to its Rust equivalent and lists where the Rust behaviour differs on purpose.
Calls
| PHP | Rust |
|---|---|
(new Generator)->generate() | let ogm = Ogm::generate(); ogm.digits() |
(new Generator)->generate(true) | Ogm::generate().to_string() |
(new Generator)->generate(false, '2026') | let ogm = Ogm::generate_with_prefix("2026")?; ogm.digits() |
(new Generator)->generate(true, '0909337554') | Ogm::from_base("0909337554")?.to_string() |
TooMuchDigits exception | Err(OgmError::PrefixTooLong { .. }) |
(new Validator)->isValid($ogm) | is_valid_structured(ogm) or Ogm::from_structured(ogm) |
(new Validator)->digitsAreValid($number) | digits_are_valid(number) or Ogm::from_digits(number) |
| none | Ogm::parse(input) / is_valid(input): any of the four forms, whitespace trimmed |
bin/ogm generate [PREFIX] | no CLI; Ogm::generate_with_prefix(prefix)?.to_string() (formatted by default) |
bin/ogm generate -c [PREFIX] | no CLI; let ogm = Ogm::generate_with_prefix(prefix)?; ogm.digits() |
bin/ogm validate OGM | no CLI; is_valid_structured(ogm) |
bin/ogm validate -c OGM | no CLI; digits_are_valid(digits) |
Rust returns an Ogm value instead of a string. Keep it as the type in your own code and format it
when you display or store it.
The random digits are not reproduced: the port does not use PHP's seeded mt_rand sequence. A 10-digit
prefix gives the same reference as PHP. With a shorter prefix, PHP's output and Rust's output each have
the right prefix and shape and pass the mod-97 check on their own; their random digits are unrelated and
are the same only by chance.
Differences
Each one is a diverged row in the package's parity.toml.
***XXX/XXXX/XXXXX***is valid. PHP'sisValidrejects it because of astr_replacebug, although its docs list both delimiters. Rust accepts both.- No trailing newline in strict mode. PHP's regex
$matches before a final\n, so PHP accepts"+++090/9337/55493+++\n".from_structuredrejects it;Ogm::parsetrims it. - Only ASCII digits. PHP's
digitsAreValidcasts with(int), soabcdefghij97passes. Rust returnsOgmError::InvalidCharacters. - Prefix type and coercion. PHP takes a string, int or
nulland throwsInvalidArgumentExceptionfor other types, but silently coerces leading spaces (" 123456789"→" 12345678939") and negative integers (-123456789→"-123456789-39") without warning, and throwsTooMuchDigitsbefore coercion on overlength non-digit prefixes ("1234567890x"). Rust takes&str, checks ASCII digits before length, and returnsOgmError::InvalidPrefixfor any non-digit character. UseOgm::generate()for no prefix. - No CLI. The crate is a library only.