Skip to content

Conversation

@WaterWhisperer
Copy link

Changes

  • Authority::from_static and PathAndQuery::from_static are now const.
  • Both perform compile-time validation equivalent to their runtime counterparts using byte-wise scanning.
  • For const panics on invalid input, uses an out-of-bounds indexing trick compatible with MSRV 1.49 .

Explanation

Uri::from_static remains non-const. Two blockers under MSRV 1.49:

  1. Const slicing of &'static str is unavailable, but Uri parsing requires slicing the input into scheme/authority/path+query.
  2. Non-standard schemes use Box, which requires allocation not allowed in const fn.

Tests

  • cargo test passed.
  • Doc tests for const usage included implicitly via examples.

Related issue

Partially fixes #750

@WaterWhisperer WaterWhisperer changed the title feat(uri): make Authority::from_static and PathAndQuery::from_static const feat(uri): make Authority/PathAndQuery::from_static const Oct 27, 2025
@WaterWhisperer
Copy link
Author

WaterWhisperer commented Nov 8, 2025

Hello @seanmonstar

This PR has been open for some time, and I'd like to politely request a review (mainly marking Authority/PathAndQuery::from_static as const, so it can be used in const contexts). Thanks!

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.

Uri/Authority/PathAndQuery::from_static should be const

1 participant