Repository navigation
feat(rs-client): Make Usecase::from_static a const fn - #712
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #712 +/- ##
==========================================
- Coverage 91.55% 91.50% -0.05%
==========================================
Files 116 116
Lines 22088 22175 +87
==========================================
+ Hits 20222 20292 +70
- Misses 1866 1883 +17
☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Semver Impact of This PRThis PR lands in these workspaces:
📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features
🤖 This preview updates automatically when you update the PR. |
objectstore-types' Usecase now stores either a &'static str or an Arc<str> and gains a const fn from_static, with validation kept private. The client forwards to it, so an invalid name in a const or static fails compilation. Co-Authored-By: Lorenzo Cian <17258265+lcian@users.noreply.github.com>
sentry-junior
Bot
force-pushed
the
feat/rust-client-const-from-static
branch
from
October 30, 2026 10:30
9120ce9 to
3c17f7e
Compare
jan-auer
marked this pull request as ready for review
October 30, 2026 11:42
InvalidUsecaseName::InvalidChar now carries the byte position of the first invalid character instead of the decoded char, so const validation needs no UTF-8 decoder. Error messages live in shared constants used by both the Display impl and the const panics in from_static, which now has #[track_caller]. Usecase::new takes impl AsRef<str> and allocates the Arc<str> once, deserialization reads the string through a visitor instead of an intermediate String, and Debug prints the name without the internal storage variant. The client's constructors share one with_name helper, and from_static gains doc examples, including a compile_fail check. BREAKING CHANGE: InvalidUsecaseName::InvalidChar holds a usize byte position instead of a char, and Usecase::new accepts impl AsRef<str> instead of impl Into<String>.
lcian
approved these changes
Oct 30, 2026
jan-auer
approved these changes
Oct 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Makes
Usecase::from_staticaconst fn, so an invalid name fails compilation when it's evaluated in a const context, and aUsecasecan live in a plainstaticwithoutLazyLock:Outside a const context it still panics at runtime, as before, now reporting the caller's location.
Most of the change is in
objectstore_types::usecase::Usecase. It now stores either a&'static stror anArc<str>and gains aconst fn from_staticalongsidenew, with validation kept private to the module.Arc::newcan't run in aconst fn, so this is what makes a const constructor possible. Equality, ordering, hashing, serialization, andDebuguse the name string, so static and dynamic names behave the same.Since validation runs in a
const fn,InvalidUsecaseName::InvalidCharnow reports the byte position of the first invalid character instead of the character, which keeps validation free of UTF-8 decoding.Usecase::newin the types crate takesimpl AsRef<str>instead ofimpl Into<String>and allocates the name once.The client only swaps its
Arc<UsecaseName>field forUsecaseNameand forwardsfrom_staticto the types crate.Changelog Entry
Usecase::from_staticis now aconst fnUsecasecan be a plainstaticwithoutLazyLock, and an invalid name fails at compile time when evaluated in a const context.InvalidUsecaseName::InvalidCharnow holds the byte position of the invalid character instead of the character.via @lcian.
--
View Junior Session [Sentry]