Rod

Numbers

Integer and float validation.

Numbers

Rod treats all numbers as double-precision floats (f64) internally but provides specific integer constraints.

number().int().min(0.0).max(100.0)
rod.number().int().min(0).max(100)
rod.number().int().min(0).max(100)

Constraints

  • .min(n): Minimum value (inclusive).
  • .max(n): Maximum value (inclusive).
  • .int(): Rejects any value with a fractional part.

Type Strictness

Rod does not perform implicit coercion by default. Passing a string "123" to a number validator will fail unless you use the coerce module.

// Fails for "123"
number().validate(&input) 

// Succeeds for "123" -> returns 123.0
rod_rs::coerce::number().validate(&input)
// Fails for "123"
rod.number().parse("123")

// Succeeds for "123"
rod.coerce.number().parse("123")
# Fails for "123"
rod.number().parse("123")

# Succeeds for "123" (Coming Soon in Python)

On this page