Skip to content

feat!: accept standard Rust ranges in ParameterBuilder::range() - #738

Open
superposition wants to merge 1 commit into
ros2-rust:mainfrom
superposition:feat/675-standard-parameter-ranges
Open

superposition wants to merge 1 commit into
ros2-rust:mainfrom
superposition:feat/675-standard-parameter-ranges

Conversation

@superposition

Copy link
Copy Markdown
Contributor

Simple bounds currently require a ParameterRange struct literal. This change lets
callers write .range(0.0..=1.0), .range(0..10), or .range(..=0) directly.
It changes the builder argument to impl Into<T::Range> and adds the six requested
standard range conversions. Conversions have no step; explicit stepped ranges remain
available. Exclusive floating-point upper bounds remain unsupported.

Exclusive integer bounds use checked subtraction. Empty or reversed integer ranges,
including an exclusive end of i64::MIN, produce DeclarationError::InvalidRange
when declared instead of overflowing or broadening the accepted values.

Closes #675.

Source compatibility

This intentionally changes type inference at the call site:

  • Replace .range(Default::default()) with a typed default such as
    .range(ParameterRange::<i64>::default()).
  • Replace .range(bounds.into()) with .range(bounds) when the intermediate type
    would otherwise be ambiguous.

The API docs contain compile-fail coverage for these cases and for both exclusive
float forms, plus compiling native-range and migration examples. Runtime tests cover
boundaries, invalid defaults, all declaration kinds, generic forwarding, a convertible
enum, unchanged stepped ranges, and ROS descriptor bounds.

Validation

Tested on Windows with native ROS 2 Jazzy and a separate generated Rust interface
overlay. The overlay was produced from installed Jazzy IDL using rosidl_generator_rs
at commit 19d57818dab3b51e418c0893b70b3a1a8b64c495.

  • Rust 1.94.1: all 134 runtime unit tests pass with serde enabled.
  • Rust 1.85.0: all 42 parameter tests pass with serde enabled.
  • All six new doctests pass on both compilers (two compiling examples and four
    expected compilation failures).
  • Nightly formatting passes for both changed Rust files; git diff --check passes.
  • Full doctests encounter 45 existing linker failures for the installed ROS library's
    missing rmw_qos_profile_best_available symbol. An unchanged snapshot of base commit
    c9b7d93 reproduces the identical failed cases. The modified tree adds six passing
    doctests, with no additional failures.
  • Clippy with --no-deps --all-targets --features serde -- -D warnings fails on the
    unchanged base too. Comparing diagnostics by message and source file shows no added
    diagnostics on either compiler: 121 on stable and 134 on Rust 1.85.
  • Full nightly formatting requests the same changes in two untouched files on both
    base and modified trees (dynamic_message/message_structure.rs and lib.rs).

Runtime test suites were run serially in separate ROS domains.

No dependency, minimum Rust version, or CI changes are included.

Assisted-by: Codex:GPT-6

Accept convertible bounds in ParameterBuilder::range and implement standard Rust
range conversions without a step. Handle exclusive integer underflow through the
existing invalid-range validation path and retain exclusive float compile errors.

Cover numeric boundaries, declaration kinds, generic forwarding, convertible enums,
ROS descriptors, and type inference migrations with tests and doctests.

BREAKING CHANGE: range arguments now use Into, so untyped defaults need a type
annotation and ambiguous explicit into calls should pass the bounds directly.

Refs: ros2-rust#675
Assisted-by: Codex:GPT-6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Accept standard Rust ranges in ParameterBuilder::range()

1 participant